[Fixed]-Why are my environment variables not detected when starting up celery?

13👍

I just discovered that I not only had to set my environment variables in the system, but I also had to pass those variables in to the /etc/default/celleryd script.

I just put my variables at the bottom of /etc/default/celleryd:

export MY_SPECIAL_VARIABLE = "my production variable"
export MY_OTHERSPECIAL_VARIABLE = "my other production variable"

2👍

if environment variables write on ~/.bashrc, you can add source ~/.bashrc to /etc/init.d/celeryd at first.

1👍

Does your /etc/default/celeryd define what user celery should run as?

In mine I have:

CELERYD_USER="celery"
CELERYD_GROUP="celery"

Can you post your /etc/defaults/celeryd config file?

👤Goro

1👍

I had the same problem using celery and supervisor, I had supervisord to use a shell script to start celery worker and also source the env variables.

#!/bin/bash

source ~/.profile
CELERY_LOGFILE=/usr/local/src/imbue/application/imbue/log/celeryd.log
CELERYD_OPTS=" --loglevel=INFO --autoscale=10,5 --concurrency=8"
cd /usr/local/src/imbue/application/imbue/conf
exec celery worker -n celeryd@%h -f $CELERY_LOGFILE $CELERYD_OPTS

in ~/.profile:

export C_FORCE_ROOT="true"
export KEY="DEADBEEF"

Leave a comment