I have a Tornado program, and all the relative python lib installed in a non-root user called bob by:
pip install --user xxx
Now I want to run it in supervisor:
[program:testpro]
command=python /path/to/myfile.py
user=bob ; set the user to bob
redirect_stderr=true
stdout_logfile=/path/to/log
numproces=1
autostart=true
but it failed, in supervisorctl status:
testpro FATAL Exited too quickly (process log may have details)
I see the log and find it can't import relative python lib, so it it not run as bob.
then I change to :
[program:testpro]
command=sudo -u bob -i python /path/to/myfile.py
;user=bob ;comment this
redirect_stderr=true
stdout_logfile=/path/to/log
numproces=1
autostart=true
and it run ok
So, what does the option user
do? and how can I config the run-as user in an option?
I have solved this problem:
add environment
option in program section:
environment=HOME="/home/bob",USER="bob"
See Supervisor doc - 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. This is particularly important to note when you are running a program from a supervisord run as root with a user= stanza in the configuration. Unlike cron, supervisord does not attempt to divine and override “fundamental” environment variables like USER, PATH, HOME, and LOGNAME when it performs a setuid to the user defined within the user= program config option. If you need to set environment variables for a particular program that might otherwise be set by a shell invocation for a particular user, you must do it explicitly within the environment= program config option. An example of setting these enviroment variables is as below.
[program:apache2]
command=/home/chrism/bin/httpd -c "ErrorLog
/dev/stdout" -DFOREGROUND user=chrism
environment=HOME="/home/chrism",USER="chrism"