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!
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.
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.
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.
The supervisor service runs automatically after installation. You can check its status: sudo systemctl status supervisor.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With