2017-02-09 81 views
0

我试图用supervisord停止NGINX时遇到错误。Supervisord - NGINX停止OSError

要启动NGINX没有错误从supervisord我曾在supervisord.conf前面加上sudo到nginx的命令:

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

当我运行此:

使用 supervisorctl何时停止过程
$ 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 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 

有没有解决方法?

+0

问题是,你为什么要在监督下启动nginx?它守护进程,这意味着它退出,supervisord会检测到失败(不是)。它必须与sudo一起运行,因为它绑定到低端口号(80和443)。重新考虑你监督守护进程的决定。为了让nginx运行,所以主管可以完成它的工作,你必须告诉它不要守护进程。 [请参考nginx文档](http://nginx.org/en/docs/faq/daemon_master_process_off.html)。 –

+0

启动nginx工程,我在nginx配置中关闭了'daemon'。问题是如何与主管一起杀死它。我想用supervisor启动/停止nginx的原因是,我需要为所有正在运行的进程(webservers,redis,rabbitmq等)启用/关闭开关,包括nginx。 –

+0

试图在黑暗中刺伤 - “sudo supervisorctl stop nginx”,你试过了吗? –

回答

0

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

...

安装监事时,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创建。但是,我们先尝试一下。

+0

尝试在我的终端中运行'pidproxy /tmp/nginx.pid sudo nginx -c \'pwd \'/ configs/nginx.conf',并没有抱怨,但我没有看到正在运行的nginx进程。 –