I am trying to start a celery worker on EB but get an error which doesn't explain much.
Command in config file in .ebextensions dir
:
03_celery_worker:
command: "celery worker --app=config --loglevel=info -E --workdir=/opt/python/current/app/my_project/"
The listed command works fine on my local machine (just change workdir parameter).
Errors from the EB:
Activity execution failed, because: /opt/python/run/venv/local/lib/python3.6/site-packages/celery/platforms.py:796: RuntimeWarning: You're running the worker with superuser privileges: this is absolutely not recommended!
and
Starting new HTTPS connection (1): eu-west-1.queue.amazonaws.com (ElasticBeanstalk::ExternalInvocationError)
I have updated celery worker command with parameter --uid=2
and privileges error disappeared but command execution is still failed due to
ExternalInvocationError
Any suggestions what I do wrong?
As I understand it means that listed command cannot be run from EB container commands. It is needed to create a script on the server and run celery from the script. This post describes how to do it.
Update: It is needed to create a config file in
.ebextensions
directory. I called itcelery.config
. Link to the post above provides a script which works almost fine. It is needed to make some minor additions to work 100% correct. I had issues with schedule periodic tasks (celery beat). Below are steps on how to fix is:Install (add to requirements) django-celery beat
pip install django-celery-beat
, add it to installed apps and use--scheduler
parameter when starting celery beat. Instructions are here.In the script you specify user which run the script. For celery worker it is
celery
user which was added earlier in the script (if doesn't exist). When I tried to start celery beat I got error PermissionDenied. It means that celery user doesn't have all necessary rights. using ssh I logged in to EB, looked a list of all users (cat /etc/passwd
) and decided to use daemon user.Listed steps resolved celery beat errors. Updated config file with the script is below (celery.config): ``` files: "/opt/elasticbeanstalk/hooks/appdeploy/post/run_supervised_celeryd.sh": mode: "000755" owner: root group: root content: | #!/usr/bin/env bash
commands: 01_killotherbeats: command: "ps auxww | grep 'celery beat' | awk '{print $2}' | sudo xargs kill -9 || true" ignoreErrors: true 02_restartbeat: command: "supervisorctl -c /opt/python/etc/supervisord.conf restart celerybeat" leader_only: true ``` One thing to focus attention on: in my project
celery.py
file is in theconfig
directory, that is why I write-A config.celery:app
when start celery worker and celery beat