简体   繁体   中英

Safely long running java process in background

I have three jar files that should run forever in background in a embedded system. I am actually do this with jamvm -jar program.jar & over a ssh-session. But the jar file exits after one day running in background and have a unpredictable behaviour. In the posts Linux: Prevent a background process from being stopped after closing SSH client they suggest nohup command > /dev/null 2>&1 & , but I also have the same behaviour. How I can safely run the jar files in background forever? How I can ensure if the jar file exits to restart it again?

Upstart , supervisor , and systemd will run a process for you and restart them if they fail. Which is available will depend on your Linux distribution and its age. There are probably also other similar services as well.

From the systemd documentation:

Restart=

Configures whether the service shall be restarted when the service process exits, is killed, or a timeout is reached. The service process may be the main service process, but it may also be one of the processes specified with ExecStartPre=, ExecStartPost=, ExecStop=, ExecStopPost=, or ExecReload=. When the death of the process is a result of systemd operation (eg service stop or restart), the service will not be restarted. Timeouts include missing the watchdog "keep-alive ping" deadline and a service start, reload, and stop operation timeouts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM