Is there a shell tool that takes an arbitrary executable and makes a detectable, restartable background process out of it?
If I had to script this myself, I would use a $PIDFILE
and something along the lines of...
if [ -f $PIDFILE ] && ps -p `cat $PIDFILE` &> /dev/null; then
# Already running, kill, restart
else
# Stale pidfile, start
fi
This sounds like there's a program that does this a thousand times better than anything I'd come up with, though. Is there?
If there isn't, what caveats and gotchas should I be aware of in implementing a script as the above?