Skip to content

Instantly share code, notes, and snippets.

@foxmask
Created November 2, 2016 14:21
Show Gist options
  • Save foxmask/f43c61b5005ad993554f9bdba2b6bfdb to your computer and use it in GitHub Desktop.
Save foxmask/f43c61b5005ad993554f9bdba2b6bfdb to your computer and use it in GitHub Desktop.
start gunicorn with initializing env var
$ cat ../bin/gunicorn_start
#!/bin/bash
source $(dirname $0)/init.cfg
echo "Starting Gunicorn for $NAME"
exec ../bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--log-level=$LOG_LEVEL \
--bind=$IP:$PORT \
--access-logfile $ACCESSFILE --error-logfile $ERRORFILE
$ cat ../bin/init.cfg
NAME="th" # Name of the application
DJANGODIR=/path/that/contains/manage.py/ # Django project directory
USER=foxmask # the user to run as
GROUP=foxmask # the group to run as
NUM_WORKERS=1 # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=th.settings # which settings file should Django use
DJANGO_WSGI_MODULE=th.wsgi # WSGI module name
IP=127.0.0.1
PORT=8080
#LOG
LOGDIR=/path/that/contains/log/of/the/app
#LOG_LEVEL=DEBUG
LOG_LEVEL=INFO
ERRORFILE="$LOGDIR$NAME-error.log"
ACCESSFILE="$LOGDIR$NAME-access.log"
HTTPS=on
# Activate the virtual environment
cd $DJANGODIR
source ../bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment