Question

I'm a celery noob at the moment, but trying to get started. I'm running Django 1.4 + django-celery + celery 3.0.21 with a redis storage backend. I can get a worker and celerybeat to run 'manually' via:

python manage.py celery worker -E -B --loglevel=INFO -n w1.manual

I want to move this into init-scripts. So, I've installed the two init scripts supplied by celery. I can run them as desired and the scripts work fine. However, the worker started by the script is failing. It doesn't appear to be finding my project's settings. Here's the contents of my configuration file at /etc/default/celeryd:

# Name of nodes to start
# here we have a single node
CELERYD_NODES="w1"

# or we could have three nodes:
#CELERYD_NODES="w1 w2 w3"

# Where to chdir at start.
CELERYD_CHDIR="/var/www/www_project_com/"

# Extra arguments to celeryd
CELERYD_OPTS="--time-limit=300 --concurrency=8"

# Name of the celery config module.
CELERY_CONFIG_MODULE="celeryconfig"

# %n will be replaced with the nodename.
CELERYD_LOG_FILE="/var/log/celery/%n.log"
CELERYD_PID_FILE="/var/run/celery/%n.pid"

# Workers should run as an unprivileged user.
CELERYD_USER="www-data"
CELERYD_GROUP="www-data"

# Name of the projects settings module
export DJANGO_SETTINGS_MODULE="settings"

my settings files is actually divided into local/production/etc. and the production settings are located here:

/var/www/www_project_com/project/settings/production.py

I've attempted to change the last line of the config file to be:

export DJANGO_SETTINGS_MODULE="project.settings.production"

But it seemed to make no difference.

I know that the init scripts are picking up the settings file /etc/default/celery because the process is using my custom-defined user and group.

It is clear that the processes are failing because the logs show:

consumer: Cannot connect to amqp://guest@127.0.0.1:5672//: [Errno 111] Connection refused.

Which I presume is a default setting. My Django project is configured to use Redis using the connection string:

BROKER_URL = 'redis://localhost:6379/0'

As another attempt to sort this out, I've tried setting the last line to:

export DJANGO_SETTINGS_MODULE="settings.production"

This results in:

[2013-07-19 05:31:48,117: ERROR/MainProcess] Unrecoverable error: ImportError('No module named settings',)

In the logs.

What am I doing wrong?

Était-ce utile?

La solution

If you want to use the DJANGO_SETTINGS_MODULE config make sure that the config for CELERY_CONFIG_MODULE is not set.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top