Primary image for Automatically Running Supervisord on Startup

Automatically Running Supervisord on Startup

I really like supervisord for long-running process management. It is Python, so it is easy to install and it is easy to script with tools like Fabric. Lately I’ve been deploying smaller Django/WSGI sites with Green Unicorn behind Nginx proxied over a Unix socket which makes for a nice little setup on shared hosting and RAM starved VPSes.

After installing supervisord with something like sudo easy_install supervisor, you’ll want to make sure it runs after you reboot your machine (and gets restarted in case it crashes). If you are on a Linux system with upstart (and have root access), you can bypass the ugly init scripts and use this simple file placed in /etc/init/supervisord.conf to manage your supervisord process:

description     "supervisord"

start on runlevel [2345]
stop on runlevel [!2345]

respawn

exec /usr/local/bin/supervisord &#8212;nodaemon &#8212;configuration /etc/supervisord.conf</code></pre></figure>


Now that it is in upstart, you can start it with the command sudo start supervisord.

If you are on shared hosting, you probably won&#8217;t have permissions to do this, but if you have access to cron, you can make sure it gets started in case the server reboots by adding this to your cron jobs:

@reboot	/my/path/to/supervisord -c /my/path/to/supervisord.conf 2>&1
In the event supervisord crashes or is killed off by a sysadmin, you’re out of luck. If this happens, you’ll want to look into having a cron job periodically poll the process pid to see if it is still alive and restart it if it is not. I haven’t needed this (yet), so that is left as an exercise for the reader :)
Peter Baumgartner

About the author

Peter Baumgartner

Peter is the founder of Lincoln Loop, having built it up from a small freelance operation in 2007 to what it is today. He is constantly learning and is well-versed in many technical disciplines including devops, …