Running a Django app with Gunicorn and Upstart

Skimmed from here, I mostly just changed the last line that starts Gunicorn from using gunicorn_django to plain gunicorn, as recommended by the Django overlords.

/etc/init/yourapp.conf:

description "Your App"
author "Your Name "

start on (net-device-up and local-filesystems)
stop on shutdown
respawn

script
    export HOME="/root/of/django/app" # i.e. where "manage.py" can be found
    export PATH="$PATH:/root/of/django/app/env/bin" # "env" is our virtualenv
    export DJANGO_SETTINGS_MODULE="settings"
    export LANG="en_US.UTF-8"
    cd $HOME
    exec $HOME/env/bin/gunicorn -b 127.0.0.1:8000 -w 1 --log-file /var/log/gunicorn/yourapp.log app
end script

app.py:

import os, sys

sys.path.insert(0, '/root/of/django/app/')
path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if path not in sys.path:
    sys.path.append(path)

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Tagged with:

Categorised as: