我正在使用supervisord来管理gearman中的工作节点。配置文件看起来像这样
[program:public_pdf_convert]
process_name = pdf_convert_%(process_num)02d
command = /usr/local/bin/php worker_pdf_convert.php
numprocs = 2
directory = /projects/mv2/deliver/batch/batch/workers/
stopsignal = INT
[program:public_video_convert]
process_name = video_convert_%(process_num)02d
command = /usr/local/bin/php worker_video_convert.php
numprocs = 4
directory = /projects/mv2/deliver/batch/batch/workers/
stopsignal = INT
当我启动主管时,工作者类型(public_video_convert)和(public_pdf_convert)分别启动4和2个进程。
现在我想停止主管,而不是杀死这六个进程。我尝试了不同的stopsignal
值而没有运气。基本上,我想在繁忙的过程中继续运行,并在完成后继续运行。这可能吗?
答案 0 :(得分:1)
您必须直接在php worker中处理信号。 Supervisord将发送指定的stopsignal
(默认为TERM
)并等待stopwaitsecs
,然后再将其删除。
为实现这一目标,我在工人中这样做:
class Worker
{
protected $shouldStop = false;
public function stop()
{
$this->shouldStop = true;
}
protected function main()
{
// You handle both SIGINT and SIGTERM and add stop method as a callback
pcntl_signal(SIGTERM, [$this, 'stop']);
pcntl_signal(SIGINT, [$this, 'stop']);
while (true) {
// Calls signal handlers for pending signals
pcntl_signal_dispatch();
if (true === $this->shouldStop) {
// handler was called
break;
}
// Do your stuff here
}
}
}