[ACCEPTED]-Start java process at boot and auto-restart on death-init.d

Accepted answer
Score: 10

The daemon function on my machine (old RedHat) does 8 not return until the executed program returns. So 7 you are going to need to have your little 6 utility script do the forking.

Try writing 5 your utility like this:

#!/bin/bash

(
    until java -Xms256m -Xmx768m -jar MyApp.jar; do
        echo "MyApp crashed with exit code $?.  Respawning... " >&2
        sleep 5
    done
) &

How this works. Putting 4 a command in parentheses starts code running 3 in a new process. You put the process in 2 the background so the original process will 1 return without waiting for it.

Score: 4

You need a java service wrapper, here is 3 a very good one... tanuki
I mean to say, you 2 don't need to reinvent the wheel, there 1 are tools out there..

More Related questions