如何在系统重启后自动运行Grails应用程序?

huangapple go评论46阅读模式
英文:

how to automatically run grails app after system reboot?

问题

我正在运行一个Grails 4.0.10应用程序,使用以下命令:

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

该应用连接到MySQL 8服务器。

当我使用以下命令重新启动系统时:

sudo reboot

在系统重新启动后,

当我使用以下命令检查运行中的进程时:

ps -aux

我没有看到应用正在运行。

我的问题是,如何确保在系统完成重新启动后,以下命令将自动执行,以便我无需在系统重新启动后手动运行此命令来启动Grails应用程序。

我感激任何帮助!谢谢!

英文:

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!

答案1

得分: 1

以上的注释是为了将解决方案记录下来,以供将来需要的人查看。

nohup 不能在系统重启后保持进程运行。为了实现这个功能,你需要设置一个服务或者使用 crontab。(可能还有其他方法。)

要配置一个 systemd 服务,有很多资源可以参考,我就不在这里重复它们的内容了。楼主在上面的评论中找到了一些有用的链接,在那里你可以找到相关信息,但一般来说,搜索“如何创建systemd服务”会得到很多有用的结果。

作为一个更简单的方法,你可以在 crontab 中添加一行(使用 crontab -e 进行编辑),它会在系统重启时调用一个脚本:@reboot /path/to/script.sh。这个脚本可以启动你需要的所有内容,比如数据库和应用程序。

个人建议使用 systemd 方法,因为它更健壮,但是 crontab 对于本地开发和测试来说已经足够了,而且可能更简单。

英文:

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.

huangapple
  • 本文由 发表于 2023年3月7日 14:19:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/75658593.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定