以root身份启动supervisord?

时间:2013-11-11 23:39:04

标签: python startup supervisord

Supervisor在3.0上运行:

pip freeze | grep supervisor
supervisor==3.0

从命令行启动supervisord时:

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

我收到此错误:

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

但是如果没有 sudo 我就无法启动监督,它会抱怨:

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

处理它的正确方法是什么?

(如果以root身份启动它,但在supervisord.conf的[supervisord]部分下设置user = foobar,我会得到同样的错误)

更新:这是我的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 个答案:

答案 0 :(得分:24)

在进行任何处理之前,Supervisord会切换到UNIX用户帐户。

您需要指定它应该使用哪种用户帐户,以root身份运行守护程序,但在配置文件中指定user

示例:

[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

访问http://supervisord.org/configuration.html#program-x-section-values了解详情

答案 1 :(得分:12)

当您以root用户身份启动主管时,出于安全原因,您需要为主管指定一个用户

来自主管文档(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.

把它放在你的conf文件中:

[supervisord]
user=nobody

用户应该是一个存在的用户,但没有sudo权限(没人可以工作)。

答案 2 :(得分:8)

对我来说,我在以非root用户身份运行时收到此错误:

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

在我将持有sock文件的目录包含给该用户之后,这就消失了。

在你的情况下:

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

chown username /opt/run/,或将文件指向用户拥有的另一个目录。

我从这个link学到了这种方法。

另外,我的系统管理员安装了我写的init.d脚本。 init.d脚本以root用户身份运行,但脚本可以使用以下命令在myuser上启动supervisord:

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

答案 3 :(得分:7)

你得到了:

根据我的理解,你得到的这条CRIT信息困扰着你:

  

以root身份运行的CRIT Supervisor(配置文件中没有用户)

括号中的单词是一个线索。此消息表明您可能以root 无意中运行Supervisor。

执行此操作:

所以解决方案很简单:告诉主管你是故意这样做的 (在/etc/supervisor/supervisord.conf

[supervisord]
user = root

以root身份运行Supervisord后,它会将uid设置为您指定的用户,即root。 (#308

不重要:

虽然现在您可能收到此消息:

  

CRIT将uid设置为用户0

不用担心,此消息应该是INFO级别而不是CRIT级别。  (#693

答案 4 :(得分:0)

我的环境:

宅基+ Laravel ubuntu18 LTS

我遇到了同样的问题,
确保控制文件属于正确的所有者。

1。初始主管必须使用root

示例:

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

您可能会终止对主管的所有处理并重新运行

2。尽量不要使用root运行作业。

我的工作伙伴为/etc/supervisor/conf.d/lara*.conf,用户无业游民

my job conf

chown日志文件到vagrant,发票文件与supervisor.conf相关

my supervisor conf

然后

运行supervisorctl status,使用vagrant

job run

相关问题