以root身份启动supervisord?

kev*_*kev 33 python startup supervisord

主管在3.0上运行:

pip freeze | grep supervisor
supervisor==3.0
Run Code Online (Sandbox Code Playgroud)

从命令行启动supervisord时:

sudo $VIRTENV/supervisord --nodaemon --configuration $PATH_TO_CONFIG/supervisord.conf
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

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

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

Error: Cannot open an HTTP server: socket.error reported errno.EACCES (13)
Run Code Online (Sandbox Code Playgroud)

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

(如果以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
Run Code Online (Sandbox Code Playgroud)

Jan*_*cak 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
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请访问http://supervisord.org/configuration.html#program-x-section-values


Ryl*_*lan 13

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

来自主管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.
Run Code Online (Sandbox Code Playgroud)

把它放在你的conf文件中:

[supervisord]
user=nobody
Run Code Online (Sandbox Code Playgroud)

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

  • 这阻止了主管能够保存到需要根级别权限的日志文件. (4认同)
  • 或者,您可以使用 `logfile=/path/to/logfile` 指定保存日志文件的目录,并确保您删除的用户具有写入该目录的权限。您也不需要转到任何人,您可以转到 ubuntu 或类似的用户。 (2认同)

Mat*_*sen 9

对我来说,我作为非root用户运行时收到此错误:

Error: Cannot open an HTTP server: socket.error reported errno.EACCES (13)
Run Code Online (Sandbox Code Playgroud)

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

在你的情况下:

[unix_http_server]
file = /opt/run/supervisord.sock
Run Code Online (Sandbox Code Playgroud)

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

我从这个链接中学到了这种方法.


另外,我的系统管理员安装了我写的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
Run Code Online (Sandbox Code Playgroud)


Kya*_*yan 8

你得到了:

根据我的理解,你收到了这条令人困扰的CRIT消息:

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

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

做这个:

因此解决方案非常简单:告诉主管您是故意这样做的.
(中/etc/supervisor/supervisord.conf)

[supervisord]
user = root
Run Code Online (Sandbox Code Playgroud)

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

不重要:

虽然现在你可能会得到这样的信息:

CRIT将uid设置为用户0

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