Last active
October 1, 2016 18:28
-
-
Save vayn/7c4ccbfc21c5274da8bc30f28bfd2cf0 to your computer and use it in GitHub Desktop.
django, gunicorn, supervisor, virtualenvwrapper settings
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
#!/bin/bash | |
NAME="hezhi" # Name of the application | |
PYTHONPATH=/home/ubuntu/.virtualenvs/hezhi/bin/python3 # Python path | |
DJANGODIR=/var/www/hezhi # Django project directory | |
SOCKFILE=/var/www/hezhi/run/gunicorn.sock # we will communicte using this unix socket | |
USER=ubuntu # the user to run as | |
GROUP=ubuntu # the group to run as | |
NUM_WORKERS=3 # how many worker processes should Gunicorn spawn | |
DJANGO_SETTINGS_MODULE=hezhi.settings # which settings file should Django use, change to | |
DJANGO_WSGI_MODULE=hezhi.wsgi # WSGI module name | |
echo "Starting $NAME as `whoami`" | |
# Activate the virtual environment | |
cd $DJANGODIR | |
source /home/ubuntu/.virtualenvs/hezhi/bin/activate | |
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE | |
export PYTHONPATH=$PYTHONPATH | |
# 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 gunicorn ${DJANGO_WSGI_MODULE}:application \ | |
--name $NAME \ | |
--workers $NUM_WORKERS \ | |
--user=$USER --group=$GROUP \ | |
--log-level=debug \ | |
--bind=unix:$SOCKFILE |
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
[program:hezhi] | |
command = /home/ubuntu/.virtualenvs/hezhi/bin/gunicorn_hezhi_start ; Command to start app | |
user = ubuntu ; User to run as | |
stdout_logfile = /var/log/supervisor/gunicorn_hezhi.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