Josh Jore
2013-12-22 16:58:56 UTC
Hi,
I have a daemonized Apache httpd which I'd like to manage with supervisord. I've just read http://supervisord.org/subprocess.html#apache-2-2-6 and http://smarden.org/runit/runscripts.html#apache2 which roughly suggest using -DFOREGROUND to prevent forking and detaching from the console.
I'm really unsure that it's smart for me to adjust this existing daemon much since it's actually a mod_perl application server with a lot of moving parts. I'd much rather just manage the program as-is, even though it detaches from its parent and is a proper daemon.
I'd like a suggestion for something that's been already worked out, preferably nicer than this terribly buggy shell script I just penned for this email.
#!/bin/sh
# TODO(jjore): handle `start | stop | status | restart`
PIDFILE=$1
SIGNAL=WINCH
if [ -r "$PIDFILE" ] && kill -0 $(cat "$PIDFLE"); then
echo "$@ is already running"
exit 1
fi
trap 'kill "-$SIGNAL" $(cat "$PIDFILE")' TERM
rm -f "$PIDFILE"
while true; do
# TODO(jjore): Avoid restarting too quickly
( exec "$@" ) &
while kill -0 $(cat "$PIDFILE") && sleep 1; do
done
wait
done
I have a daemonized Apache httpd which I'd like to manage with supervisord. I've just read http://supervisord.org/subprocess.html#apache-2-2-6 and http://smarden.org/runit/runscripts.html#apache2 which roughly suggest using -DFOREGROUND to prevent forking and detaching from the console.
I'm really unsure that it's smart for me to adjust this existing daemon much since it's actually a mod_perl application server with a lot of moving parts. I'd much rather just manage the program as-is, even though it detaches from its parent and is a proper daemon.
I'd like a suggestion for something that's been already worked out, preferably nicer than this terribly buggy shell script I just penned for this email.
#!/bin/sh
# TODO(jjore): handle `start | stop | status | restart`
PIDFILE=$1
SIGNAL=WINCH
if [ -r "$PIDFILE" ] && kill -0 $(cat "$PIDFLE"); then
echo "$@ is already running"
exit 1
fi
trap 'kill "-$SIGNAL" $(cat "$PIDFILE")' TERM
rm -f "$PIDFILE"
while true; do
# TODO(jjore): Avoid restarting too quickly
( exec "$@" ) &
while kill -0 $(cat "$PIDFILE") && sleep 1; do
done
wait
done