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 --nodaemon --configuration /etc/supervisord.conf 

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’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 :)

Comments

  • June 24, 2010 at 12:56 p.m. #
    Simon Luijk chimed in with:

    I am using daemontools to monitor gunicorn. When I update my code I send gunicorn a SIGHUP to gracefully reload the code. This creates all sorts of problems. As expected gunicorn starts up a new process and then shuts the original process down. At which point daemontools tries to start gunicorn as it thinks gunicorn has died. I have a tempary hack which I’ll spare you from.

    I have been looking for an alternative and supervisord is high on the list but I have not been able to find anything conclusive on sending signals to monitored processes. What is your experience in getting gunicorn to gracefully reload code with your setup?

  • June 25, 2010 at 4:48 a.m. #
    ZeissS responded:

    @Simon: You could use the supervisorctl tool to signal supervisord to restart the process.

  • June 28, 2010 at 1:57 a.m. #
    Simon Luijk responded:

    @ZeissS That would stop and start the process and not gracefully reload the code.

    I guess my question is does supervisord get its knickers in a twist if I “kill -HUP `cat /tmp/gunicorn.pid`” like daemontools does?

    Seeing that you can’t give supervisord a pid file for a process, I guess the answer is yes.

Got something to say?





Our Products

Gondola
Gondola is a hosted CMS that gives designers a powerful and easy platform to create amazing geo-enabled Websites.
Trailmapping
Still in development, Trailmapping is a GPS enabled trail guide and trip logger.

Categories

Archives

Elsewhere

What we’ve been up to online

Interested in working with us?
Fill out the form below or contact us at:

PO Box 774441
Steamboat Springs, CO
80477

ph: 970.879.8810
fx:  970.367.8596
info@lincolnloop.com