Last active
February 10, 2017 08:31
-
-
Save ninjadq/b284bf7dc3be9b1a78d7933ce18a44d9 to your computer and use it in GitHub Desktop.
script for django celery and gunicorn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo 'kill celery workers....\n' | |
kill `cat celeryd.pid` | |
sleep 2.5 | |
echo 'kill celerybeat....' | |
kill `cat celerybeat.pid` | |
sleep 1 | |
echo 'start celery worker...' | |
celery -A monitorsystem worker -l error --detach --logfile="celeryworker.log" | |
sleep 1 | |
echo 'start celery beat...' | |
celery -A monitorsystem beat --detach --logfile="celerybeat.log" -l info | |
sleep 2.5 | |
ps aux | grep celery | |
echo 'done' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
NAME="monitorsystem" # Name of the application | |
DJANGODIR=/usr/local/monitorsystem/ # Django project directory | |
SOCKFILE=/usr/local/monitorsystem/run/gunicorn.sock # we will communicte using this unix socket | |
VENV=/usr/local/monitorsystem/venv | |
USER=root # the user to run as | |
GROUP=root # the group to run as | |
NUM_WORKERS=4 # how many worker processes should Gunicorn spawn | |
DJANGO_SETTINGS_MODULE=monitorsystem.settings # which settings file should Django use | |
DJANGO_WSGI_MODULE=monitorsystem.wsgi # WSGI module name | |
echo "Starting $NAME as `whoami`" | |
# Activate the virtual environment | |
cd $DJANGODIR | |
source /usr/local/monitorsystem/venv/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 $VENV/bin/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=- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment