【问题标题】:Supervisord - NGINX stop OSErrorSupervisord - NGINX 停止 OSError
【发布时间】:2017-02-09 20:01:20
【问题描述】:

尝试使用supervisord 停止NGINX 时遇到错误。

要从supervisord 无错误地启动NGINX,我必须在supervisord.conf 的nginx 命令前添加sudo

[supervisord]
[program:nginx]
command=sudo nginx -c %(ENV_PWD)s/configs/nginx.conf

当我运行这个时:

$ supervisord -n
2017-02-09 12:26:06,371 INFO RPC interface 'supervisor' initialized
2017-02-09 12:26:06,372 INFO RPC interface 'supervisor' initialized
2017-02-09 12:26:06,372 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2017-02-09 12:26:06,373 INFO supervisord started with pid 22152
2017-02-09 12:26:07,379 INFO spawned: 'nginx' with pid 22155
2017-02-09 12:26:08,384 INFO success: nginx entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)

^C # SIGINT: Should stop all processes

2017-02-09 13:59:08,550 WARN received SIGINT indicating exit request
2017-02-09 13:59:08,551 CRIT unknown problem killing nginx (22155):Traceback (most recent call last):
  File "/Users/ocervell/.virtualenvs/ndc-v3.3/lib/python2.7/site-packages/supervisor/process.py", line 432, in kill
    options.kill(pid, sig)
  File "/Users/ocervell/.virtualenvs/ndc-v3.3/lib/python2.7/site-packages/supervisor/options.py", line 1239, in kill
    os.kill(pid, signal)
OSError: [Errno 1] Operation not permitted

使用supervisorctl 停止进程时相同:

$ supervisorctl stop nginx
FAILED: unknown problem killing nginx (22321):Traceback (most recent call last):
  File "/Users/ocervell/.virtualenvs/ndc-v3.3/lib/python2.7/site-packages/supervisor/process.py", line 432, in kill
    options.kill(pid, sig)
  File "/Users/ocervell/.virtualenvs/ndc-v3.3/lib/python2.7/site-packages/supervisor/options.py", line 1239, in kill
    os.kill(pid, signal)
OSError: [Errno 1] Operation not permitted

有解决办法吗?

【问题讨论】:

  • 问题来了,为什么要带监督启动nginx呢?它守护进程,这意味着它退出并且 supervisord 将检测为失败(它不是)。它必须使用 sudo 运行,因为它绑定到低端口号(80 和 443)。重新考虑您监督该守护程序的决定。为了让 nginx 运行以便主管可以完成它的工作,你必须告诉它不要守护进程。 Refer to this, from nginx docs.
  • 启动 nginx 工作,我在 nginx 配置中有 'daemon off'。问题是如何用主管杀死它。我想用主管启动/停止 nginx 的原因是我需要为我正在运行的所有进程(webservers、redis、rabbitmq 等)设置一个开/关开关,包括 nginx。
  • 只是想在这里暗中刺伤 - sudo supervisorctl stop nginx,你试过了吗?
  • 是的,它返回相同的错误OSError

标签: nginx supervisord


【解决方案1】:

如果supervisord创建的进程创建了自己的子进程,supervisord不能杀死它们。

...

在安装 supervisor 时,pidproxy 程序被放入你配置的 $BINDIR 中(它是一个“控制台脚本”)。[1]

所以你要做的就是像这样改变你的supervisord配置:

[program:nginx]
command=/path/to/pidproxy /path/to/nginx-pidfile sudo nginx -c %(ENV_PWD)s/configs/nginx.conf

这也可能不起作用,因为 nginx 进程是由 sudo 创建的。不过还是先试试吧。

【讨论】:

  • 尝试在我的终端中运行pidproxy /tmp/nginx.pid sudo nginx -c `pwd`/configs/nginx.conf,没有抱怨,但我没有看到 nginx 进程正在运行。
猜你喜欢
  • 2015-09-25
  • 2013-01-06
  • 2012-02-23
  • 1970-01-01
  • 1970-01-01
  • 2013-09-26
  • 2016-12-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多