Whys is Celery worker using /root as home directory?

1.8k Views Asked by At

We are using Celery and RabbitMQ to process jobs. They are both being run by Supervisor so that they can be alive.

Some jobs expect a file in the home directory of a user A. So we run the celery worker as user A in supervisor. But when the job is being processed it is expanding the '~' as '/root'. Why is this happening? How can we ensure that it is able to find the home directory by expanding '~' as our code expects files following a '~' in a lot of places?

1

There are 1 best solutions below

2
On BEST ANSWER

You probably need to use supervisord's user configuration directive to run the celery processes as a dedicated user instead of root.

also you should explicity chdir to a working dir - either in your celery code or use the supervisor directory setting.

If you want to rely on ~ working you should probably set the invironment variable $HOME also. However ~ is a shell expansion which may not always work. The most portable solution is to rely on the directory setting.

/etc/supervisor.d/celery.conf

[program:celery]
command=/path/to/celery worker
user=celery
stdout_logfile=/var/log/supervisor/celery.log
redirect_stderr=true
directory=/path/to/celery/working/dir
environment=HOME=/path/to/celery/home