问题描述
我最近使用 PHP5-FPM、Gearman 和 Supervisor 设置了 Ubuntu Natty.我已经编辑了我的 Supervisord 配置来运行一个 Gearman 工作器.
I recently set up Ubuntu Natty with PHP5-FPM, Gearman, and Supervisor. I've edited my Supervisord config to run a Gearman worker.
[program:gearman]
command=/usr/bin/php php_gearman_worker.php
numprocs=1
directory=/root/sandbox
stdout_logfile=/root/sandbox/supervisord.log
environment=GEARMAN_USER=gearman
autostart=true
autorestart=true
user=gearman
这是我在运行 supervisord 之前 lsof -i -P
时的相关信息(仅显示 gearmand 和 php 进程):
Here's the relevant info (showing only gearmand and php processes) when I lsof -i -P
before I run supervisord:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
gearmand 29314 gearman 6u IPv4 328139 0t0 TCP localhost:4730 (LISTEN)
这是我在 /etc/init.d/supervisor stop && 之后
.lsof -i -P
得到的结果/etc/init.d/supervisor start
And here's what I get when I lsof -i -P
after I /etc/init.d/supervisor stop && /etc/init.d/supervisor start
.
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
gearmand 29314 gearman 6u IPv4 328139 0t0 TCP localhost:4730 (LISTEN)
gearmand 29314 gearman 11u IPv4 328206 0t0 TCP localhost:4730->localhost:39072 (ESTABLISHED)
php 29571 gearman 4u IPv4 329744 0t0 TCP localhost:39072->localhost:4730 (ESTABLISHED)
我没有看到 supervisord 本身的任何列表,我应该将 supervisord 视为命令之一吗?!
I don't see any listing for supervisord itself, should I see supervisord as one the commands?!
无论如何,当我再次停止并启动(或重新启动)supervisord 时:
Anyway, when I stop and start (or restart) supervisord again:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
gearmand 29314 gearman 6u IPv4 328139 0t0 TCP localhost:4730 (LISTEN)
gearmand 29314 gearman 11u IPv4 328206 0t0 TCP localhost:4730->localhost:39072 (ESTABLISHED)
gearmand 29314 gearman 12u IPv4 329754 0t0 TCP localhost:4730->localhost:51570 (ESTABLISHED)
php 29571 gearman 4u IPv4 329744 0t0 TCP localhost:39072->localhost:4730 (ESTABLISHED)
php 29619 gearman 4u IPv4 327233 0t0 TCP localhost:51570->localhost:4730 (ESTABLISHED)
看起来每次我停止和启动 supervisord 时,它都会创建另一个 php 进程,然后是另一个.只有当我重新启动 gearmand 时它才会恢复正常,即 /etc/init.d/gearman-job-server stop &&/etc/init.d/gearman-job-server start
.
It looks like with each time I stop and start supervisord, it creates another php process, and then another. It's only when I restart gearmand that it goes back to normal i.e. /etc/init.d/gearman-job-server stop && /etc/init.d/gearman-job-server start
.
这对我来说似乎不正常,因为当我停止 supervisord 时,它应该停止
This seems abnormal to me being that when I stop supervisord, it's supposed to stop
这是 supervisord 的工作方式吗?!有什么办法可以防止这种情况发生吗?!
Is this the way supervisord works?! Is there a way I can prevent this from happening?!
提前致谢.
编辑
我发现了导致问题的原因.这是与 supervisord.conf 和我的 init 脚本的一个小冲突.
I found out what was causing the problem. It was a small conflict with the supervisord.conf and my init script.
我的 supervisord.conf 文件有以下设置:
My supervisord.conf file had the following settings:
pidfile=/tmp/supervisord.pid
但是我在 /etc/init.d/supervisord
的 init 脚本有以下设置:
But my init script at /etc/init.d/supervisord
had the following setting:
NAME=supervisord
PIDFILE=/var/run/$NAME.pid
所以我只是更改了 supervisord.conf 中的设置以匹配我的 init 脚本中的设置.
So I just changed the setting in supervisord.conf to match what was in my init script.
此外,我将 stopsignal=KILL
添加到我的 supervisord 配置文件 (supervisord.conf) 中的程序配置中.
Also, I added stopsignal=KILL
to the program config in my supervisord config file (supervisord.conf).
感谢 Minaz 的指导.
Thanks to Minaz for the direction.
推荐答案
我总是为我的主管配置文件包含 stopsignal 配置选项.这允许在请求停止时终止 gearman 进程.试试这个:
I always include the stopsignal config option for my supervisor config files. This allows the gearman process to be killed when a stop is requested. Try this:
[program:gearman]
command=/usr/bin/php php_gearman_worker.php
numprocs=1
directory=/root/sandbox
stdout_logfile=/root/sandbox/supervisord.log
environment=GEARMAN_USER=gearman
autostart=true
autorestart=true
user=gearman
stopsignal=KILL
这篇关于Supervisord 为 PHP 和 Gearman 添加多个进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!