Forked from m0n5t3r/gunicorn-upstart.conf.template
Created
February 26, 2012 00:23
-
-
Save achew22/1911810 to your computer and use it in GitHub Desktop.
template for a gunicorn upstart job that can run several instances of a django application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# %(mysite)s - run %(mysite)s instances (default is the main production instance) | |
# | |
# This runs gunicorn-django for %(mysite)s; to install: | |
# * sudo ln -s <this file> /etc/init/%(mysite)s | |
# * sudo initctl reload-configuration | |
# | |
# it expects the following directory layout: | |
# | |
# /home/%(mysite)s/public_html | |
# \-env -> virtualenv | |
# | \-bin | |
# | \-gunicorn_django | |
# | \-activate | |
# \-<instance> | |
# | \-app -> application | |
# | \-conf | |
# | | \-gunicorn_<instance>.conf.py | |
# | | \-<this file> | |
# | \-log -> logs | |
# | \-run -> pid files and the like | |
# \-<instance> | |
# ... | |
# | |
# to use: | |
# * sudo start/stop/restart/reload/status %(mysite)s | |
# * sudo start/stop/restart/reload/status %(mysite)s instance=testing | |
description "%(mysite)s gunicorn instance, default is the main instance" | |
start on runlevel [2345] | |
stop on runlevel [06] | |
expect fork | |
respawn | |
respawn limit 10 5 | |
instance ${instance:-main} | |
env APPHOME="/home/%(mysite)s/public_html" | |
pre-start script | |
INST=${instance:-main} | |
GUNICORN="$APPHOME/env/bin/gunicorn_django" | |
test -n "$GUNICORN" -a -x "$GUNICORN" || { stop; exit 0; } | |
test -d "$APPHOME" || { stop; exit 0; } | |
end script | |
script | |
INST=${instance:-main} | |
CONF="$APPHOME/$INST/conf/gunicorn_$INST.conf.py" | |
GUNICORN="$APPHOME/env/bin/gunicorn_django" | |
PIDFILE="$APPHOME/$INST/run/$INST.pid" | |
LOGFILE="$APPHOME/$INST/log/gunicorn.log" | |
cd "$APPHOME/$INST/app" | |
source "$APPHOME/" | |
exec $GUNICORN --pid="$PIDFILE" --name="$INST" --user=django --group=django --config="$CONF" --daemon --log-file="$LOGFILE" 2>>"$LOGFILE" | |
end script | |
post-stop script | |
INST=${instance:-main} | |
rm -rf "$APPHOME/$INST/run/$INST".{pid,sock} | |
end script | |
# vim: set et sw=4 ts=4 sts=4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment