Skip to content

Instantly share code, notes, and snippets.

@CMCDragonkai
Last active May 18, 2021 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save CMCDragonkai/3d844144d582f095cd55 to your computer and use it in GitHub Desktop.
Save CMCDragonkai/3d844144d582f095cd55 to your computer and use it in GitHub Desktop.
Upstart: Upstart Init Script for Supervisord
# 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 /
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment