Wednesday 11 July 2012

Webfaction - Installing & Configuring Supervisor

Supervisord is a process control system and it’s jazz to work with. It allows you to control processes programatically via an xml-rpx interface (which I don’t tend to use) or via a cli interface supervisorctl. Typically I tend to use it to manage gunicorn django processes.


Installing on webfaction is a breeze, once you’ve got pip installed it’s case of –

 pip install supervisor 


I like to keep my config files in ~/local/etc but supervisor looks in ~/etc for the supervisord.conf config file. This presents to options. I could supply the config file at runtime, but I don’t like doing this because it ‘feels’ a bit sloppy. The second option (my preferred method) is to symlink ~/local/etc/ to ~/etc/

 ln -s ~/local/etc ~/etc 

Now it’s case of whipping together a config file. Here’s one that I like to start off with something like this for my ~/etc/supervisord.conf file –

 [unix_http_server] file=/home/you/tmp/supervisor.sock [supervisord] logfile=/home/you/tmp/supervisord.log logfile_maxbytes=50MB logfile_backups=10  loglevel=info pidfile=/home/you/tmp/ [rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [supervisorctl] serverurl=unix:///home/you/tmp/supervisor.sock [include] files = /home/you/etc/supervisord/*.ini 

I like to include the individual files for processes in my config because I tend to bundle them with (along with other app stuff like requirements.txt) in the app repository. Some folks don’t like doing this and I can see why, but I find bundling keeps everything nice and clean; once you get past the ‘dirtiness’ of bundling config with application. I digress.

Running Supervisord

That’s easy –


Watch Out

Beware installing it into a virtualenv because then it’ll only be accessible inside that virtualenv. This won’t be a problem if you’re only managing one project with supervisors, but given webfaction’s generous 256Mb memory allowance you can comfortably run two or three django apps.