Created
March 7, 2017 21:35
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
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 myapp --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
reference
http://serebrov.github.io/html/2015-04-02-elastic-beanstalk-python.html
http://stackoverflow.com/questions/14761468/how-do-you-run-a-worker-with-aws-elastic-beanstalk
http://stackoverflow.com/questions/25214876/worker-dyno-in-aws-elastic-beanstalk/25215196#25215196
https://gist.github.com/Azrael808/8fbfb57041367d4b045ae43485783f18