Celery-Django as Daemon: Settings not found

All answers here could be a part of the solution but at the end, it was still not working. But I finally succeeded to make it work.

First of all, in /etc/init.d/celeryd, I have changed this line:

CELERYD_MULTI=${CELERYD_MULTI:-"celeryd-multi"}

by:

CELERYD_MULTI=${CELERYD_MULTI:-"celery multi"}

The first one was tagged as deprecated, could be the problem.

Moreover, I put this as option: CELERYD_OPTS="--app=myapp"

And don't forget to export some environments variables:

# Name of the projects settings module.
export DJANGO_SETTINGS_MODULE="myapp.settings"
export PYTHONPATH="$PYTHONPATH:/home/ubuntu/myapp-folder"

With all of this, it's now working on my side.


The problem is most likely that celeryd can't find your Django settings file because myapp.settings isn't in the the $PYTHONPATH then the application runs.

From what I recall, Python will look in the $PYTHONPATH as well as the local folder when importing files. When celeryd runs, it likely checks the path for a module app, doesn't find it, then looks in the current folder for a folder app with an __init__.py (i.e. a python module).

I think that all you should need to do is add this to your /etc/default/celeryd file:

export $PYTHONPATH:path/to/your/app