supervisord 管理多进程程序如 pyspider 时的合适配置
现在的工程中,有一部分是用 pyspider 来抓取数据的,使用 supervisord 来管理它的进程。在使用过程中,遇到一个奇怪的问题:用supervisorctl stop pyspider
之后,pyspider 并未全部停止,而是留下了三四个进程在系统中。
查阅官方手册,在 [program:x] Section Settings 中找到了名为 stopasgroup
的选项,解释如下:
If true, the flag causes supervisor to send the stop signal to the whole process group and implies
killasgroup
is true. This is useful for programs, such as Flask in debug mode, that do not propagate stop signals to their children, leaving them orphaned.
在 [program:pyspider] 小节,开启这个选项。如:
[program:pyspider] command=/home/oott123/pyspider/run.py autorestart=true startsecs=2 user=oott123 directory=/home/oott123/pyspider/ redirect_stderr=true stopasgroup=true environment=WEBUI_HOST="127.0.0.1",WEBUI_PORT="5033"
然后重启 supervisord ,再测试停止 pyspider 的服务,它就不会残留那几个进程了。