38
votes

Supervisor is running on 3.0:

pip freeze | grep supervisor
supervisor==3.0

When starting supervisord from the command line:

sudo $VIRTENV/supervisord --nodaemon --configuration $PATH_TO_CONFIG/supervisord.conf

I get this error:

2013-11-11 23:30:50,205 CRIT Supervisor running as root (no user in config file)

But I can't start supervisord without sudo, it complains:

Error: Cannot open an HTTP server: socket.error reported errno.EACCES (13)

What is the right way to deal with it?

(I get the same error if starting it as root but setting user = foobar under the [supervisord] section in supervisord.conf)

Update: Here is my supervisord.conf

[unix_http_server]
file = /opt/run/supervisord.sock

[inet_http_server]
port = 9001
username = foobar
password = foobar

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

[supervisord]
logfile = /opt/logs/supervisord.log
loglevel = debug
pidfile = /opt/run/supervisord.pid

[supervisorctl]

[program:foo1]
user = foobar
autostart = True
autorestart = True
command = foo1
stdout_logfile = /opt/logs/foo1.stdout.log
stderr_logfile = /opt/logs/foo1.stderr.log
stdout_logfile_maxbytes = 10MB
stderr_logfile_maxbytes = 10MB

[program:foo2]
user = foobar
autostart = true
autorestart = true
command = foo2
priority = 100
stdout_logfile_backups = 0
stderr_logfile_backups = 0
stdout_logfile_maxbytes = 10MB
stderr_logfile_maxbytes = 10MB
stdout_logfile = /opt/logs/foo2.stdout.log
stderr_logfile = /opt/logs/foo2.stderr.log
5
Are you sure you want to start another copy of the supervisord daemon, rather than running supervisorctl or something? What exactly are you trying to do here?abarnert
I don't try to start multiple copies of supervisord, just one. As I wrote, I am confused. Starting supervisord as root gives me a CRIT, but I can't start it as non-root.kev
Does it work when you remove the [inet_http_server] section?pors
I am wondering the same thing. The doc is not clear on that and seeing the CRIT error makes me wonder as well if it's not better to run supervisor with a supervisor user created for this purpose. What did you end up doing? Thanks.Michael
TL;DR set user=root in supervisord.conf. (Explanation)Kyan

5 Answers

27
votes

Supervisord switches to UNIX user account before any processing.

You need to specify what kind of user account it should use, run the daemon as root but specify user in the config file

Example:

[program:myprogram]
command=gunicorn --worker-class socketio.sgunicorn.GeventSocketIOWorker app.wsgi:application -b 127.0.0.1:8000
directory=/opt/myprogram
user=user1
autostart=true
autorestart=true
redirect_stderr=True

Visit http://supervisord.org/configuration.html#program-x-section-values for more information

14
votes

When you start supervisor as root, you need to specify a user for supervisor to drop to for security reasons

From the supervisor docs (http://supervisord.org/configuration.html):

user
If supervisord is run as the root user, switch users to this UNIX user account before doing any meaningful processing. 
This value has no effect if supervisord is not run as root.

Put this in your conf file:

[supervisord]
user=nobody

The user should be a user which exists, but does not have sudo permissions (nobody can work).

12
votes

For me, I received this error while running as a non-root user:

Error: Cannot open an HTTP server: socket.error reported errno.EACCES (13)

This went away after I chowned the directory holding the sock file to that user.

In your case:

[unix_http_server]
file = /opt/run/supervisord.sock

Either chown username /opt/run/, or point the file to another directory that is owned by the user.

I learned this approach from this link.


Additionally, my sysadmins installed an init.d script I wrote. The init.d script is run as root, but the script can get supervisord to start on myuser with this command:

SUPERVISORD=/path/to/supervisord
PIDFILE=/path/to/supervisord.pid
OPTIONS='-c /path/to/supervisord.conf'
daemon --pidfile=$PIDFILE --user=myuser $SUPERVISORD $OPTIONS
12
votes

You got:

Per my understanding, you got this CRIT message which is bothering you:

CRIT Supervisor running as root (no user in config file)

The words in brackets is a clue. This message indicates that you may be running Supervisor as root unintentionally.

Do this:

So the solution is pretty simple: Tell Supervisor that you are doing this intentionally.
(in /etc/supervisor/supervisord.conf)

[supervisord]
user = root

Once you run Supervisord as root, it sets uid to the user you assigned, which is, root. (#308)

Not important:

Although now you may get this message:

CRIT Set uid to user 0

No worries, this message should be a INFO level rather than a CRIT level. (#693)

0
votes

My environment :

Homestead+laravel ubuntu18 LTS

I had the same problem,
Be sure to control that the file belongs to the correct owner.

1.Starting supervisor must use root

example:

vagrant@homestead:~$ sudo supervisord -c /etc/supervisord.conf
vagrant@homestead:~$ ps -aux|grep supervisord
root     12145  0.0  0.8  71144 16744 ?        Ss   07:20   0:00 /usr/bin/python /usr/bin/supervisord -c /etc/supervisord.conf

you may kill all processing of supervisor and re-run

2.Try not to use root run job.

My job conf is /etc/supervisor/conf.d/lara*.conf,user is vagrant

my job conf

chown log file to vagrant,invole file related supervisor.conf

my supervisor conf

then

run supervisorctl status use vagrant

job run