javalinuxdaemonapache-commons-daemon

Java service on Linux - How to ensure constant uptime. Deamon, Shell script or Wrapper?


I have a Java worker that are polling a external queue system for jobs, through web service calls.

What is the most solid way to ensure that the worker is operating at any given time?


Solution

  • JVM execution is not different from any other program. So what you want to do is to put together a shell script and place it in /etc/init.d and link it appropriatelly to to /etc/rc.d. On RedHat flavors it will ensure service startup with the system.

    Wring the script may be tricky, but I would copy one of existing ones and change it to call java executable with right parameters. In this script you would have to capture java process id. You can use it then to monitor your process and restart as necessary.