Chris Lamb

Sysadmin-friendly deployment of Gunicorn in Debian

Over the last 18 months Gunicorn has replaced mod_wsgi as the de facto container for deploying Django projects.

However, whilst it was first uploaded to Debian in April 2010, it was not particularly sysadmin friendly. In particular, it required custom initscripts (or some other mechanism) to manage each Gunicorn instance.

To improve that, you can now place multiple configuration files inside /etc/gunicorn.d:

# /etc/gunicorn.d/django.example: defaults are commented out

CONFIG = {
    'mode': 'django',
    'environment': {
        'PYTHONPATH': '/path/to/custom/python/packages',
    },
    # 'working_dir': '/',
    # 'user': 'www-data',
    # 'group': 'www-data',
    'args': (
        # '--bind=127.0.0.1:8000',
        '--workers=4',
        # '--worker-class=egg:gunicorn#sync',
        # '--timeout=30',
       'settings',
    ),
}

All instances can then be restarted using:

$ /etc/init.d/gunicorn restart
Stopping Gunicorn workers: [example] [site_a] [site_b].
Starting Gunicorn workers: [example] [site_a] [site_b].

Sites using plain WSGI can use the wsgi mode - see /etc/gunicorn.d/wsgi.example.


Chris Lamb is a freelance Django developer and Debian developer. You can read other posts by me, see software I have written or read more about me. You can also follow me @lolamby.


Tags: Hacks Django GNU/Linux

Planets: WUGLUG UWCS Debian ALUG

Sunday 31st July 2011


Three comments