1

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?

1
  • Use the Java Service Wrapper to make a proper daemon.
    – bmargulies
    Commented Jul 14, 2016 at 18:37

1 Answer 1

0

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 (e.g. 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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.