If the script returns exit codes as specified in the answer at that link, then it should work. If you go back and read that answer again, it implies that you should not use kill
. Using until
will test for startup because a failed startup should return a non-zero exit code. Replace "myserver" with the name of your script.
Your script can have traps that handle various signals and other conditions. Those trap handlers can set appropriate exit codes.
Here is a demo. The subshell (echo "running 'dummy'"; sleep 2; exit $result)
is a standin for your script:
result=0
until (echo "running 'dummy'"; sleep 2; exit $result)
do
echo "Server 'dummy' crashed with exit code $?. Respawning.." >&2
sleep 1
done
Try it with a failing "dummy" by setting result=1
and running the until
loop again.