Last active
October 27, 2020 06:34
-
-
Save nmfzone/3dd8207bc8c56ad9a75bcdf1059ca45e to your computer and use it in GitHub Desktop.
Django Production Simple Configuration using Supervisor + Gunicorn + Celery + Flower + Pyenv Virtualenv
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
########## DO NOT INCLUDE THIS ########## | |
# File Location: /etc/supervisor/conf.d/celery-beat-appcom.conf | |
######################################### | |
[program:celery_beat_appcom] | |
process_name=%(program_name)s | |
command=/home/johndoe/django-app/celery-beat/run-appcom-celery-beat.sh | |
startsecs=10 | |
autostart=true | |
autorestart=true | |
stopasgroup=true | |
stderr_logfile=/var/log/django/celery-beat/appcom.log | |
stdout_logfile=/var/log/django/celery-beat/appcom.out.log |
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
########## DO NOT INCLUDE THIS ########## | |
# File Location: /etc/supervisor/conf.d/celery-worker-appcom.conf | |
######################################### | |
[program:celery_worker_appcom] | |
process_name=%(program_name)s | |
command=/home/johndoe/django-app/celery-beat/run-appcom-celery-worker.sh | |
startsecs=10 | |
autostart=true | |
autorestart=true | |
stopasgroup=true | |
stderr_logfile=/var/log/django/celery-worker/appcom.log | |
stdout_logfile=/var/log/django/celery-worker/appcom.out.log |
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
########## DO NOT INCLUDE THIS ########## | |
# File Location: /etc/supervisor/conf.d/flower-appcom.conf | |
######################################### | |
[program:flower_appcom] | |
process_name=%(program_name)s | |
command=/home/johndoe/django-app/flower/run-appcom-flower.sh | |
autostart=true | |
autorestart=true | |
stopasgroup=true | |
stderr_logfile=/var/log/django/flower/appcom.log | |
stdout_logfile=/var/log/django/flower/appcom.out.log |
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
########## DO NOT INCLUDE THIS ########## | |
# File Location: /etc/supervisor/conf.d/gunicorn-appcom.conf | |
######################################### | |
[program:gunicorn_appcom] | |
process_name=%(program_name)s | |
command=/home/johndoe/django-app/gunicorn/run-gunicorn-appcom.sh | |
autostart=true | |
autorestart=true | |
stderr_logfile=/var/log/django/gunicorn/appcom.log | |
stdout_logfile=/var/log/django/gunicorn/appcom.out.log |
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
########## DO NOT INCLUDE THIS ########## | |
# File Location: /home/johndoe/django-app/celery-beat/run-appcom-celery-beat.sh | |
######################################### | |
#!/bin/bash | |
APPDIR="/home/johndoe/django-app/app.com" | |
PYENV_DIR="/home/johndoe/.pyenv/versions/app.com" | |
cd $APPDIR | |
exec ${PYENV_DIR}/bin/celery -A core beat -l INFO |
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
########## DO NOT INCLUDE THIS ########## | |
# File Location: /home/johndoe/django-app/celery-worker/run-appcom-celery-worker.sh | |
######################################### | |
#!/bin/bash | |
APPDIR="/home/johndoe/django-app/app.com" | |
PYENV_DIR="/home/johndoe/.pyenv/versions/app.com" | |
cd $APPDIR | |
exec ${PYENV_DIR}/bin/celery -A core worker -l INFO |
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
########## DO NOT INCLUDE THIS ########## | |
# File Location: /home/johndoe/django-app/flower/run-appcom-flower.sh | |
######################################### | |
#!/bin/bash | |
APPDIR="/home/johndoe/django-app/app.com" | |
PYENV_DIR="/home/johndoe/.pyenv/versions/app.com" | |
cd $APPDIR | |
exec ${PYENV_DIR}/bin/celery -A core flower --port=5001 |
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
########## DO NOT INCLUDE THIS ########## | |
# File Location: /home/johndoe/django-app/gunicorn/run-gunicorn-appcom.sh | |
######################################### | |
#!/bin/bash | |
NAME="AppCom" | |
APPDIR=/home/johndoe/django-app/app.com | |
SOCKFILE=/tmp/django-appcom.sock | |
USER=johndoe | |
GROUP=www-data | |
NUM_WORKERS=3 | |
TIMEOUT=400 | |
DJANGO_SETTINGS_MODULE=core.settings | |
DJANGO_WSGI_MODULE=core.wsgi | |
PYENV_PATH=/home/johndoe/.pyenv/versions/app.com | |
echo "Starting $NAME as `whoami`" | |
cd $APPDIR | |
source ${PYENV_PATH}/bin/activate | |
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE | |
exec ${PYENV_PATH}/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \ | |
--name $NAME \ | |
--workers $NUM_WORKERS \ | |
--user=$USER \ | |
--group=$GROUP \ | |
--bind=unix:$SOCKFILE \ | |
--access-logfile ${APPDIR}/logs/gunicorn.access.log \ | |
--error-logfile ${APPDIR}/logs/gunicorn.error.log \ | |
--log-level=debug \ | |
--timeout $TIMEOUT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you guys need to somehow have a command to re-run the migrations, you can refer to the
migratefresh
command here:https://gist.github.com/nmfzone/0b6ac9b631a6ad4c1985b9eeb0497564