Created
October 9, 2016 12:53
-
-
Save vayn/23335759fae9db7245a4e24f36af7116 to your computer and use it in GitHub Desktop.
Django+Supervisor+Gunicorn
This file contains 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
#!/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 |
This file contains 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
[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