-
Notifications
You must be signed in to change notification settings - Fork 2
/
gunicorn_start
executable file
·39 lines (36 loc) · 1.74 KB
/
gunicorn_start
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env bash
# gunicorn_start
# Author: Michael Stealey <[email protected]>
NAME="hydroshare_app" # Name of the application
DJANGODIR=/hydroshare # Django project directory
SOCKFILE=/hs_tmp/gunicorn.sock # we will communicate using this unix socket
USER=hydro-service # the user to run as
GROUP=storage-hydro # the group to run as
NUM_WORKERS=$(python -c "exec(\"import multiprocessing\nprint( multiprocessing.cpu_count() * 2 + 1)\")")
# how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=hydroshare.settings # which settings file should Django use
DJANGO_WSGI_MODULE=hydroshare.wsgi # WSGI module name
GUNICORN_LOG=/hydroshare/log/gunicorn.log # path to logfile
TIMEOUT_PERIOD=300 # timeout period in seconds
MAX_REQUESTS=1000 # maximum number of requests a worker will process before restarting
### Do not edit below this line ###
echo "Starting $NAME as `whoami`"
# Activate the virtual environment
cd $DJANGODIR
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
exec gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--worker-class gevent \
--user $USER \
--group $GROUP \
--bind unix:$SOCKFILE \
--log-level debug \
--log-file $GUNICORN_LOG \
--timeout $TIMEOUT_PERIOD \
--max-requests $MAX_REQUESTS