Skip to content

Instantly share code, notes, and snippets.

@fellipeh
Created December 21, 2015 10:33
Show Gist options
  • Save fellipeh/7dcd148414c984e2de87 to your computer and use it in GitHub Desktop.
Save fellipeh/7dcd148414c984e2de87 to your computer and use it in GitHub Desktop.
#!/bin/bash
2 NAME="site1"
3 HOME_SITE=/home/ubuntu/sites
4 HOME_VENV=/home/ubuntu/.virtualenvs/$NAME
5 DJANGODIR=$HOME_SITE/$NAME/app # Django project directory
6 SOCKFILE=$HOME_SITE/$NAME/run/gunicorn.sock # we will communicte using this un$
7 LOGFILE=$HOME_SITE/$NAME/log/gunicorn.log
8 USER=ubuntu # the user to run as
9 GROUP=ubuntu # the group to run as
10 NUM_WORKERS=3 # how many worker processes should Gunicorn spawn
11 DJANGO_SETTINGS_MODULE=site1.settings # which settings file should $
12 DJANGO_WSGI_MODULE=site1.wsgi # WSGI module name
13
14 echo "Starting $NAME as `whoami`"
15
16 # Activate the virtual environment
17 cd $DJANGODIR
18 source $HOME_VENV/bin/activate
19 export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
20 export PYTHONPATH=$DJANGODIR:$PYTHONPATH
21
22 # Create the run directory if it doesn't exist
23 RUNDIR=$(dirname $SOCKFILE)
24 test -d $RUNDIR || mkdir -p $RUNDIR
25
26 # Programs meant to be run under supervisor should not daemonize themselves (do$
27
28 # --user=$USER --group=$GROUP \
29 # --log-level=debug \
30 # --access-logfile=$LOGFILE \
31 exec $HOME_VENV/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
32 --name $NAME \
33 --workers $NUM_WORKERS \
34 --user=$USER --group=$GROUP \
35 --bind=unix:$SOCKFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment