Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incorrect user for supervisor'd celeryd

I have some periodic tasks that I run with celery (daemonized by supervisord), but after trying to create a directory in the home dir for the user i setup for the supervisor'd process I got a "permission denied" error. After looking at the os.environ dict in a running celery task I noticed that the USER var is set to 'root' and not the user that I set up in my supervisord config for celery.

This is what my /usr/local/etc/supervisord.conf looks like:

[unix_http_server]
file=/tmp/supervisor.sock
chmod=0777

[supervisord]
logfile=/var/log/supervisord.log
pidfile=/var/run/supervisord.pid

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock

[program:celery]
command=/home/<USER>/.virtualenvs/sync/bin/celeryd --beat --loglevel=INFO
environment=PYTHONPATH=/home/<USER>/apps/sync
directory=/home/<USER>/apps/sync
user=<USER>
numprocs=1
stdout_logfile=/var/log/celeryd.log
stderr_logfile=/var/log/celeryd.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs = 30

What could be causing this? Any help would be super appreciated!

like image 459
jmagnusson Avatar asked Jan 27 '12 14:01

jmagnusson


People also ask

What user does Supervisord run as?

To be able to run any subprocess as a different user from what supervisord is running as, you must run supervisord as root. It tells you if you run multiple subprocesses, you have to run as a root to be able to start all the subprocesses, meaning that if you have more than 2 projects in you supervisord.

How do I start a Supervisord process?

To start supervisord, run $BINDIR/supervisord. The resulting process will daemonize itself and detach from the terminal. It keeps an operations log at $CWD/supervisor. log by default.

What is Supervisord in Linux?

In Linux, Supervisor is a client/server system that allows its users to monitor and control a number of processes on Linux or UNIX-like operating systems. Whenever we want, Processes can be stopped and started as a unit. It starts its sub-processes via fork/exec.

How do I know if Supervisorctl is running?

The supervisor service runs automatically after installation. You can check its status: sudo systemctl status supervisor.


1 Answers

I believe this is caused by the fact that you didn't set the HOME and USER environment variables. This is necessary when using the "user=" option if your subprocess relies on those being set.

After supervisord documentation on Subprocess Environment:

No shell is executed by supervisord when it runs a subprocess, so environment variables such as USER, PATH, HOME, SHELL, LOGNAME, etc. are not changed from their defaults or otherwise reassigned

So perhaps try:

environment=USER=<USER>,HOME=/home/<USER>,PYTHONPATH=/home/<USER>/apps/sync
like image 154
kgr Avatar answered Sep 25 '22 18:09

kgr