0

I am running a grails 4.0.10 app using the following command.

nohup java -Dgrails.env=prod -Duser.timezone=US/Mountain -jar RCRoadRaceWeb4-0.1.jar &

The app connects to mysql 8 server.

When i reboot the system using the command

sudo reboot

after the system reboots.

when i check the running processes using

ps -aux

I dont see the app running.

My question is how can i make sure after the system completes rebooting the command

nohup java -Dgrails.env=prod -Duser.timezone=US/Mountain -jar RCRoadRaceWeb4-0.1.jar &

gets executed automatically so that i dont have to manually run this command after system reboot to start the grails app.

I appreciate any help! Thanks!

kofhearts
  • 3,607
  • 8
  • 46
  • 79
  • nohup doesn't cause something to run after a reboot. What did you add to make the process run after a reboot? Perhaps something in cron, or a system.d service? – Daniel Mar 07 '23 at 22:12
  • @Daniel the app doesnt run after reboot. only mysql runs after reboot. i am trying to figure out how to make the app run after reboot. – kofhearts Mar 08 '23 at 01:30
  • You'll need to either use a systemd service (more complicated, better control over dependencies) or just an @reboot line in your crontab. This example may be helpful, but there are plenty of others if not, now that you have some things to search for! Good luck! https://unix.stackexchange.com/questions/667725/how-to-start-command-after-reboot-in-ubuntu-crontab-and-rc-local-are-not-worki – Daniel Mar 08 '23 at 16:05
  • @Daniel thanks! i used the cron reboot technique. the app runs fine now after reboot but i am getting communication link failure errors in the log. maybe this is because the app is run first and then mysql fires up. how can i make sure the app runs only after mysql is up and running? thanks! – kofhearts Mar 15 '23 at 07:02
  • Two approaches, one "best" and one "simpler and probably good enough if it's not a production system". Best: create systemd services and have your application's service depend on the mysql service. Honestly this is pretty simple (google: how to create systemd service) but is a few extra steps. Simpler: write a shell script that starts things in whatever order you want, and has "sleep 30" or whatever in it to wait a bit. Call that on startup. That's far more hacky, and won't be reliable in the long term (or, will be fragile) but might get you up and running for now. – Daniel Mar 15 '23 at 16:04
  • @Daniel Thank you very much! ill try the systemd service approach today. could you write this in answer? ill accept the answer. Thanks! – kofhearts Mar 16 '23 at 01:23
  • Thank you . it worked like magic! – kofhearts Mar 16 '23 at 05:53
  • i used this approach https://www.shubhamdipt.com/blog/how-to-create-a-systemd-service-in-linux/ – kofhearts Mar 16 '23 at 05:53
  • also helpful https://medium.com/@benmorel/creating-a-linux-service-with-systemd-611b5c8b91d6 – kofhearts Mar 16 '23 at 05:53

1 Answers1

1

Documenting comments from above for anyone in the future, as they ended up providing a solution.

nohup doesn't keep a process running through a reboot. To accomplish that, you'll need to either set up a service or use crontab. (There are probably other ways as well.)

To configure a systemd service, there are many resources here and elsewhere; I will not repeat their contents here. OP found some useful links that are included in the comments above, for however long they stay available but in general searching for "how to create a systemd service" will lead to helpful results.

As a simpler approach, you may add a line to crontab (crontab -e to edit) which will call a script on reboot: @reboot /path/to/script.sh This script can start whatever you need, such as both a database and application.

Personally I would recommend the systemd approach as it is more robust, but crontab is perfectly sufficient for local development and testing, and probably simpler.

Daniel
  • 3,312
  • 1
  • 14
  • 31