July 31st 2011

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.




You can subscribe to new posts via email or RSS.