1

I have .jar file that I would like to run when the default user logs in. The .jar contains battery simulator that is for my energy management system. I have to run it with sudo so it can open ports for modbus communication. Also it requires GUI to run so it can't be run in a headless mode. I wrote a following .sh script to make run it:

#!/bin/bash
cd /usr/BatterySim+Demo/
export DISPLAY=:0.0
sudo java -jar BatterySim.jar

I made this script executable and when I right click on it and choose Run as a Program, it opens a terminal window and runs my app after providing root password. So far I tried:

  • adding it to cron(@reboot root /usr/BatterySim+Demo/BatSim.sh)
  • adding as service wrapper to systemctl
  • adding it to Startup Applications Preferences

systemctl service wrapper code:

[Unit]
Description=BMZ battery simulator Service

[Service] Type=notify ExecStart=/bin/bash -c "/usr/BatterySim+Demo/BatSim.sh" #StandardOutput=null Restart=on-failure

Increase the default a bit in order to allow many simultaneous

files to be monitored, we might need a lot of fds.

[Install] WantedBy=multi-user.target

nothing worked. Do you have any other ideas that I could try?

1 Answers1

0

Test to have the script run when the user logs into their graphical session by adding it to the .profile or .bashrc file in their home page: Do this by opening a terminal and running:

nano ~/.profile

And adding to the end of the file:

/home/user/script.sh &

The & character specifies that it runs in the background to avoid blocking the session.

Edited

If that doesn't work, try adding it to ~/.bashrc:

nano ~/.bashrc

And finally, add:

/home/user/script.sh &

Save and try opening a new terminal.

kyodake
  • 17,808