Skip to content

Instantly share code, notes, and snippets.

@mortn
Last active August 29, 2015 14:10
Show Gist options
  • Save mortn/1f1febef27a61ab8212f to your computer and use it in GitHub Desktop.
Save mortn/1f1febef27a61ab8212f to your computer and use it in GitHub Desktop.
Method for starting a Mezzanine/Django site via Upstart script on Ubuntu 14.04
#!/bin/bash
set -e
NUM_WORKERS=3
USER=www-data
GROUP=users
DIR=$(dirname $0)
APPNAME=${DIR##*/}
LOGFILE=/var/log/gunicorn/$APPNAME.log
LOGDIR=$(dirname $LOGFILE)
cd $DIR
[ -d $(dirname $LOGFILE) ] || mkdir -p $(dirname $LOGFILE)
[ -f ../bin/activate ] || exit 42
source ../bin/activate
[ -x ../bin/gunicorn_django ] || exit 43
exec ../bin/gunicorn_django -w $NUM_WORKERS \
--user=$USER --group=$GROUP --log-level=debug \
--log-file=$LOGFILE 2>>$LOGFILE
description "Djablo instance"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
respawn limit 10 5
env NUM_CORES="$(cat /proc/cpuinfo | grep processor | wc -l)"
export NUM_CORES
exec /www/django/mezzanine/djablo.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment