Skip to content

Instantly share code, notes, and snippets.

@nmfzone
Last active October 27, 2020 06:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nmfzone/3dd8207bc8c56ad9a75bcdf1059ca45e to your computer and use it in GitHub Desktop.
Save nmfzone/3dd8207bc8c56ad9a75bcdf1059ca45e to your computer and use it in GitHub Desktop.
Django Production Simple Configuration using Supervisor + Gunicorn + Celery + Flower + Pyenv Virtualenv
########## 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
########## 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
########## 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
########## 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
########## 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
########## 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
########## 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
########## 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
@nmfzone
Copy link
Author

nmfzone commented Oct 27, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment