Skip to content

Instantly share code, notes, and snippets.

@katoozi
Created May 15, 2019 12:12
Show Gist options
  • Save katoozi/01628c368b9cd3595a37ec4304167f29 to your computer and use it in GitHub Desktop.
Save katoozi/01628c368b9cd3595a37ec4304167f29 to your computer and use it in GitHub Desktop.
simple gunicorn file
#!/bin/bash
NAME="django_project" # Name of the application
DJANGODIR=/var/www/django_project # Django project directory
SOCKFILE=/var/www/django_env/run/gunicorn.sock # we will communicte using this unix socket
USER=root # the user to run as
GROUP=root # the group to run as
NUM_WORKERS=3 # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=django_project.settings # which settings file should Django use
DJANGO_WSGI_MODULE=django_project.wsgi # WSGI module name
echo "Starting $NAME as `whoami`"
# Activate the virtual environment
cd $django_project
source /var/www/django_env/bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$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 \
--bind=unix:$SOCKFILE \
--log-level=debug \
--log-file=-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment