Skip to content

Instantly share code, notes, and snippets.

@marcusshepp
Last active November 1, 2023 07:53
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcusshepp/129c822e2065e20122d8 to your computer and use it in GitHub Desktop.
Save marcusshepp/129c822e2065e20122d8 to your computer and use it in GitHub Desktop.
Django Gunicorn Daemon Script
# django gunicorn script
# Generates a Daemon process with Gunicorn.
# see processes with ps -aux
# tested on: Ubuntu 14.04.3 LTS (GNU/Linux 3.13.0-74-generic x86_64), aws ec2
# Runs on apps built with Django==1.9
# Marcus Shepherd <marcusshepdotcom@gmail.com>
# 3-12-16
NAME=project # REPLACE WITH BASE DIR NAME
SETTINGS=$NAME.settings
SOCK=/opt/proc/$NAME-gunicorn.sock
PID=/opt/proc/$NAME-gunicorn.pid
LOGFILE=/opt/proc/$NAME-gunicorn.log
WORKERS=3
echo 'Creating Daemon process for: '$NAME
echo 'LOGFILE: '$LOGFILE
# this is where .sock .log and .pid get put
DIRECT=/opt/proc/
if ! [[ -d $DIRECT ]]; then
ls -la /opt/
echo $DIRECT" does not exist.. creating.."
sudo mkdir $DIRECT
ls -la /opt/
else
echo "Yes it does."
echo "removing /opt/proc/$NAME*"
rm -rf /opt/proc/$NAME*
fi
gunicorn \
--env DJANGO_SETTINGS_MODULE=$SETTINGS \
$NAME.wsgi:application \
--pid $PID \
--bind unix:$SOCK \
--workers $WORKERS \
--name $NAME \
--daemon \
--log-file=$LOGFILE
# run from /opt/project
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment