Created
May 15, 2019 00:21
-
-
Save bahiamartins/8c7b59c4143a1f1818c662912ab165f8 to your computer and use it in GitHub Desktop.
Daemonization process of Celery and Celery Beat using Supervisord in AWS Elastic Beanstalk
This file contains hidden or 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
files: | |
"/tmp/100_celery_worker.sh": | |
mode: "000755" | |
owner: root | |
group: root | |
content: | | |
#!/bin/sh | |
# for_log_and_pid | |
mkdir -p /var/log/celery/ /var/run/celery/ | |
chmod 777 -R /var/run/celery/ | |
# Get django environment variables | |
celeryenv=`cat /opt/python/current/env | tr '\n' ',' | sed 's/export //g' | sed 's/$PATH/%(ENV_PATH)s/g' | sed 's/$PYTHONPATH//g' | sed 's/$LD_LIBRARY_PATH//g' | sed 's/%/%%/g'` | |
celeryenv=${celeryenv%?} | |
# Create celery configuraiton script | |
celerydconf="[program:celery-worker] | |
; Set full path to celery program if using virtualenv | |
#replace [PROJ] with your project name | |
command=/opt/python/run/venv/bin/celery worker -A [PROJ] -P solo --loglevel=INFO | |
directory=/opt/python/current/app | |
user=nobody | |
numprocs=1 | |
stdout_logfile=/var/log/celery/worker.log | |
stderr_logfile=/var/log/celery/worker.log | |
autostart=true | |
autorestart=true | |
startsecs=10 | |
; Need to wait for currently executing tasks to finish at shutdown. | |
; Increase this if you have very long running tasks. | |
stopwaitsecs = 600 | |
; When resorting to send SIGKILL to the program to terminate it | |
; send SIGKILL to its whole process group instead, | |
; taking care of its children as well. | |
killasgroup=true | |
; Set Celery priority higher than default (999) | |
; so, if rabbitmq is supervised, it will start first. | |
priority=998 | |
environment=$celeryenv | |
[program:celery-beat] | |
; Set full path to celery program if using virtualenv | |
command=/opt/python/run/venv/bin/celery beat -A [PROJ] --loglevel=INFO -s /var/run/celery/celerybeat-schedule --pidfile="/var/run/celery/celerybeat.pid" | |
directory=/opt/python/current/app | |
user=nobody | |
numprocs=1 | |
stdout_logfile=/var/log/celery-beat.log | |
stderr_logfile=/var/log/celery-beat.log | |
autostart=true | |
autorestart=true | |
startsecs=10 | |
; Need to wait for currently executing tasks to finish at shutdown. | |
; Increase this if you have very long running tasks. | |
stopwaitsecs = 600 | |
; When resorting to send SIGKILL to the program to terminate it | |
; send SIGKILL to its whole process group instead, | |
; taking care of its children as well. | |
killasgroup=true | |
; if rabbitmq is supervised, set its priority higher | |
; so it starts first | |
priority=998 | |
environment=$celeryenv" | |
# Create the celery supervisord conf script | |
echo "$celerydconf" | tee /opt/python/etc/celeryd.conf | |
# Add configuration script to supervisord conf (if not there already) | |
if ! grep -Fxq "[include]" /opt/python/etc/supervisord.conf | |
then | |
echo "[include]" | tee -a /opt/python/etc/supervisord.conf | |
echo "files: celeryd.conf" | tee -a /opt/python/etc/supervisord.conf | |
fi | |
# Reread the supervisord config | |
/usr/local/bin/supervisorctl -c /opt/python/etc/supervisord.conf reread | |
# Update supervisord in cache without restarting all services | |
/usr/local/bin/supervisorctl -c /opt/python/etc/supervisord.conf update | |
# Start/Restart celeryd through supervisord | |
/usr/local/bin/supervisorctl -c /opt/python/etc/supervisord.conf restart celery-worker | |
/usr/local/bin/supervisorctl -c /opt/python/etc/supervisord.conf restart celery-beat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment