Supervisord 为 PHP 和 Gearman 添加多个进程

发布于 2024-12-18 09:58:05 字数 2582 浏览 4 评论 0原文

我最近使用 PHP5-FPM、Gearman 和 Supervisor 设置了 Ubuntu Natty。我已经编辑了 Supervisord 配置来运行 Gearman 工作程序。

[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 进程):

COMMAND     PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
gearmand  29314  gearman    6u  IPv4 328139      0t0  TCP localhost:4730 (LISTEN)    

这是我在 lsof -i -P 时得到的信息在我 /etc/init.d/supervisor 停止之后 && /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 视为命令之一吗?!

无论如何,当我再次停止并启动(或重新启动)supervisord 时:

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启动

这对我来说似乎很不正常,因为当我停止supervisord时,它应该停止

这是supervisord的工作方式吗?!有什么办法可以防止这种情况发生吗?!

提前致谢。

编辑

我找出了导致问题的原因。这是与supervisord.conf 和我的初始化脚本的一个小冲突。

我的supervisord.conf 文件有以下设置:

pidfile=/tmp/supervisord.pid

但是我在 /etc/init.d/supervisord 的初始化脚本有以下设置:

NAME=supervisord
PIDFILE=/var/run/$NAME.pid

所以我只是更改了supervisord.conf 中的设置以匹配中的设置我的初始化脚本。

另外,我将 stopsignal=KILL 添加到了 Supervisord 配置文件 (supervisord.conf) 的程序配置中。

感谢米纳兹的指导。

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

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)    

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)

I don't see any listing for supervisord itself, should I see supervisord as one the commands?!

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)

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.

This seems abnormal to me being that when I stop supervisord, it's supposed to stop

Is this the way supervisord works?! Is there a way I can prevent this from happening?!

Thanks in advance.

EDIT

I found out what was causing the problem. It was a small conflict with the supervisord.conf and my init script.

My supervisord.conf file had the following settings:

pidfile=/tmp/supervisord.pid

But my init script at /etc/init.d/supervisord had the following setting:

NAME=supervisord
PIDFILE=/var/run/$NAME.pid

So I just changed the setting in supervisord.conf to match what was in my init script.

Also, I added stopsignal=KILL to the program config in my supervisord config file (supervisord.conf).

Thanks to Minaz for the direction.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兔姬 2024-12-25 09:58:05

我总是在我的主管配置文件中包含 stopsignal 配置选项。这允许在请求停止时终止 gearman 进程。试试这个:

[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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文