Skip to content

Instantly share code, notes, and snippets.

@vayn
Created October 9, 2016 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vayn/23335759fae9db7245a4e24f36af7116 to your computer and use it in GitHub Desktop.
Save vayn/23335759fae9db7245a4e24f36af7116 to your computer and use it in GitHub Desktop.
Django+Supervisor+Gunicorn
#!/bin/bash
NAME="myproject"
VIRTURLROOT=/home/ubuntu/.virtualenvs/hezhi
DJANGODIR=/var/www/hezhi
SOCKFILE=/var/www/hezhi/run/gunicorn.sock
USER=ubuntu
GROUP=ubuntu
NUM_WORKERS=3
DJANGO_SETTINGS_MODULE=hezhi.settings.dev
DJANGO_WSGI_MODULE=hezhi.wsgi
echo "Starting $NAME as `whoami`"
# Activate the virtual environment
cd $DJANGODIR
source ${VIRTURLROOT}/bin/activate
export PYTHONPATH=${VIRTURLROOT}/bin/python
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
# Create the run directory if it doesn't exist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR
# Start your Django Unicorn
# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)
exec ${VIRTURLROOT}/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--log-level=debug \
--bind=unix:$SOCKFILE
[program:myproject]
command = /home/demo/webapps/myproject/bin/gunicorn_start ; Command to start app
user = demo ; User to run as
stdout_logfile = /home/demo/webapps/myproject/logs/gunicorn_supervisor.log ; Where to write log messages
redirect_stderr = true ; Save stderr in the same log
autostart = true
autorestart = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment