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
Got something to say?
Our Products
Categories
- accessiblity
- code
- company news
- django
- gondola
- open source
- portfolio
- presentation
- pro tip
- review
- screencast
- seo
- software
- subversion
- trailmapping
- wordpress
Archives
- July, 2010
- June, 2010
- May, 2010
- April, 2010
- February, 2010
- December, 2009
- November, 2009
- October, 2009
Elsewhere
What we’ve been up to online
-
I'll be trying to make dinner reservations for folks at #djangocon tonight. Restaurant recommendations in Portland?
Pete, 8 hours ago -
forked divio/django-cms
Pete, 6 days, 10 hours ago -
Congrats on the new hires @eldarion_team ! Glad to see more growth in Django commercial services.
Pete, 1 week, 4 days ago -
Video: The amazing John Cleese shares his wisdom…
Pete, 1 week, 4 days ago -
Video: The amazing John Cleese shares his wisdom…
Pete, 1 week, 4 days ago -
@caktusgroup Congrats on the new hire! Great to see the growth of other Django development companies.
Pete, 3 weeks, 4 days ago -
Just launched a Flask/App Engine mini-site we've been tinkering on http://emailed-me.appspot.com/
Pete, 1 month, 1 week ago -
created repository Emailed-Me-
Pete, 1 month, 1 week ago -
Our first iPhone development project hit the App Store last week and is already over 1k users! Check them out @takemyspot #iphone #geodjango
Pete, 2 months ago -
Love the new sites! RT @welikesmall: We just launched two new sites. http://post.ly/mGoq
Pete, 2 months ago -
Pro tip: Using pip safely for automated deployment (no more pesky prompts) http://bit.ly/b5zsPa
Pete, 2 months, 1 week ago -
commented on justquick/django-mailfriend
Pete, 2 months, 1 week ago -
RT @unbracketed: Excited to have @mitsuhiko joining us for some work this summer :)
Pete, 2 months, 2 weeks ago -
New blog post: managing supervisord with upstart http://bit.ly/db3p5N
Pete, 2 months, 2 weeks ago -
Troubleshooting OpenID is just like user/password. Except you have 5 of them and and you don't know which one is failing, and 3 login pages
Pete, 2 months, 2 weeks ago


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?
@Simon: You could use the supervisorctl tool to signal supervisord to restart the process.
@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.