My Celery works well in CLI mode:
- My project folder is organised this way:
jive/jive.py
jive.py file looks like:
app = Celery(include=['tasks.dummy_tasks','tasks.people_tasks',])
app.config_from_object(CELERY_CONFIG_PATH)
I run a worker in CLI this way:
celery worker -A jive
and it works when I'm inside thejive
folder.
Recently, I tried to daemonize Celery using systemd.
For this, 2 files are required. I will paste the important part only for both:
/etc/celery/conf.d
CELERYD_NODES="w1"
CELERY_BIN="/home/user1/venv/bin/celery"
CELERY_APP="jive"
CELERYD_MULTI="multi"
/etc/systemd/system/celery.service
[Service]
Type=forking
User=user1
EnvironmentFile=-/etc/celery/conf.d
WorkingDirectory=/home/user1
ExecStart=/bin/sh -c '${CELERY_BIN} multi start ${CELERYD_NODES} \
-A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \
--logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'
When running the service, it fails with the following errors after displaying status:
(venv) [user1@localhost jive]$ systemctl status celery.service
● celery.service - Celery Service
Loaded: loaded (/etc/systemd/system/celery.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Tue 2017-03-07 14:59:56 CET; 2s ago
Process: 16493 ExecStart=/bin/sh -c ${CELERY_BIN} multi start ${CELERYD_NODES} -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS} (code=exited, status=1/FAILURE)
Mar 07 14:59:56 localhost.localdomain sh[16493]: File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked
Mar 07 14:59:56 localhost.localdomain sh[16493]: ImportError: No module named 'jive'
Mar 07 14:59:56 localhost.localdomain sh[16493]: celery multi v4.0.2 (latentcall)
AttributeError: 'module' object has no attribute 'celery'
-> I suspect a PATH problem but not sure how to deal with this in a service. Thanks for your help.