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

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

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.

Comments (3)

Perfect. Was looking for an init.d script for gunicorn.
I'll have to install gunicorn again using the debian packages instead of pip, but the integrated service part is worth changing my deployscript.

Thanks for sharing ;)

Jan. 17, 2013, 3:10 p.m. #
Yes, as you'll need the Debian initscript and the Python code to deal with /etc/gunicorn.d, you will be much better off moving to the Debian packages.

How do you add system hook like when_ready? I'm googling and googling but nobody use sysadmin for gunicorn...

Feb. 6, 2013, 11:48 p.m. #
What's when_ready?

March 14, 2013, 8:12 p.m. #