Intro
用 Ubuntu 的 upstart 守護 supervisord
Solution
# /etc/init/supervisord.conf
# supervisord - Upstarts the supervisor as service
# Put this file into /etc/init/supervisord.conf
# sudo service supervisord start
# sudo service supervisord stop
# Service gets started as root
# Needs `pgrep` available to root
description "Supervisord - Upstart"
stop on runlevel [016]
kill timeout 8
respawn
# change this to the directory which hosts the supervisord conf file
chdir /etc/supervisor/
env DAEMON=supervisord
# due to forking bug https://bugs.launchpad.net/upstart/+bug/406397/ this hack needs to be done
# 1. starts the daemon and a sleep operation keeping up with the daemon
# 2. stop will stop the sleep operation and manually stop the daemon
pre-start script
exec $DAEMON
end script
script
sleepWhileAppIsUp(){
while pgrep $1 >/dev/null; do
sleep 1
done
}
sleepWhileAppIsUp $DAEMON
end script
post-stop script
if pgrep $DAEMON;
then
kill `pgrep $DAEMON`
fi
end script
刷新配置使其生效即可
# 刷新配置
initctl reload-configuration
# 加入 supervisord
initctl start supervisord