Skip to content

Instantly share code, notes, and snippets.

@Azrael808
Last active Aug 13, 2017
Embed
What would you like to do?
Elastic Beanstalk Customisation for running the Django CeleryD in the background.
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/99_run_supervised_celeryd.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
# Get django environment variables
celeryenv=`cat /opt/python/current/env | tr '\n' ',' | sed 's/export //g' | sed 's/%/%%/g' | sed 's/$PATH/%(ENV_PATH)s/g' | sed 's/$PYTHONPATH//g' | sed 's/$LD_LIBRARY_PATH//g'`
celeryenv=${celeryenv%?}
# Create celery configuration script
celeryconf="[program:celeryd]
; Set full path to celery program if using virtualenv
command=/opt/python/run/venv/bin/celery worker -A renuval_api --loglevel=INFO
directory=/opt/python/current/app
user=wsgi
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
; if rabbitmq is supervised, set its priority higher
; so it starts first
priority=998
environment=$celeryenv"
# Create the celery supervisord conf script
echo "$celeryconf" | tee /opt/python/etc/celery.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: celery.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 start celeryd
"/opt/elasticbeanstalk/hooks/appdeploy/pre/00_stop_celeryd.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
# Check for supervisord celery config
if [[ -f /opt/python/etc/celery.conf ]]
then
# Attempt to stop Celery
/usr/local/bin/supervisorctl -c /opt/python/etc/supervisord.conf stop celeryd
fi
"/opt/elasticbeanstalk/hooks/configdeploy/pre/00_stop_celeryd.sh":
mode: "120400"
content: "/opt/elasticbeanstalk/hooks/appdeploy/pre/00_stop_celeryd.sh"
"/opt/elasticbeanstalk/hooks/configdeploy/post/99_run_supervised_celeryd.sh":
mode: "120400"
content: "/opt/elasticbeanstalk/hooks/appdeploy/post/99_run_supervised_celeryd.sh"
"/opt/elasticbeanstalk/hooks/postinit/99_run_supervised_celeryd.sh":
mode: "120400"
content: "/opt/elasticbeanstalk/hooks/appdeploy/post/99_run_supervised_celeryd.sh"
"/opt/elasticbeanstalk/hooks/postinitreboot/99_run_supervised_celeryd.sh":
mode: "120400"
content: "/opt/elasticbeanstalk/hooks/appdeploy/post/99_run_supervised_celeryd.sh"
"/opt/elasticbeanstalk/hooks/restartappserver/pre/00_stop_celeryd.sh":
mode: "120400"
content: "/opt/elasticbeanstalk/hooks/appdeploy/pre/00_stop_celeryd.sh"
"/opt/elasticbeanstalk/hooks/restartappserver/post/99_run_supervised_celeryd.sh":
mode: "120400"
content: "/opt/elasticbeanstalk/hooks/appdeploy/post/99_run_supervised_celeryd.sh"
commands:
00_fix_perms:
command: "chmod 755 /opt/elasticbeanstalk/hooks/appdeploy/pre/00_stop_celeryd.sh /opt/elasticbeanstalk/hooks/appdeploy/post/99_run_supervised_celeryd.sh"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment