Systemd导致多个主pipe进程

我有一个问题缩小问题是我的主pipeconfiguration,导致程序被复制。

我正在通过Nginx反向代理运行Python Tornado Web服务器。 不过,我认为这个问题更多的与主pipe有关。

/etc/supervisor/supervisord.conf

[unix_http_server] file=/var/run/supervisor.sock chmod=0700 [supervisord] logfile=/var/log/supervisor/supervisord.log pidfile=/var/run/supervisord.pid childlogdir=/var/log/supervisor logfile_maxbytes=50MB logfile_backups=5 loglevel=error [rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [supervisorctl] serverurl=unix:///var/run/supervisor.sock [include] files = /etc/supervisor/conf.d/*.conf 

/etc/supervisor/conf.d/tornado.conf

 [program:tornado] numprocs = 4 numprocs_start = 8000 process_name = %(program_name)s_%(process_num)02d directory=/home/username/webapp environment=PATH="/home/username/.virtualenvs/tornado_env/bin" command = python server.py --port=%(process_num)s user=www-data redirect_stderr=true stdout_logfile=/var/log/webapp/%(program_name)s_%(process_num)02d.log loglevel=info 

正如你可以看到numprocs = 4 ,但是在刚刚重启服务器之后,我的困惑就来自于这个。

ps -aux | egrep“supervisor | python”

 root 399 0.1 2.6 14496 9584 ? Ss 15:48 0:03 /usr/bin/python /usr/bin/supervisord -c /etc/supervisor/supervisord.conf www-data 410 0.1 3.9 16872 14200 ? S 15:48 0:02 python server.py --port=8002 www-data 411 0.1 3.9 16872 14180 ? S 15:48 0:02 python server.py --port=8003 www-data 412 0.1 3.9 16872 14124 ? S 15:48 0:02 python server.py --port=8000 www-data 413 0.1 3.9 16872 14180 ? S 15:48 0:02 python server.py --port=8001 www-data 489 0.0 3.0 16872 11024 ? S 15:49 0:00 python server.py --port=8003 www-data 490 0.0 3.1 16872 11228 ? S 15:49 0:00 python server.py --port=8000 www-data 491 0.0 3.1 16872 11244 ? S 15:49 0:00 python server.py --port=8002 www-data 492 0.0 3.0 16872 11192 ? S 15:49 0:00 python server.py --port=8001 

有8个Python进程,但是主pipe只知道4个。我还要找什么?

sudo supervisorctl状态

 tornado:tornado_8000 RUNNING pid 412, uptime 0:36:03 tornado:tornado_8001 RUNNING pid 413, uptime 0:36:03 tornado:tornado_8002 RUNNING pid 410, uptime 0:36:05 tornado:tornado_8003 RUNNING pid 411, uptime 0:36:04 

更新 :以某种方式运行supervisorsystemd产卵重复的configuration。 所以现在我的问题是我禁用supervisor服务,如果是的话,那么还有什么导致它启动?

sudo systemctl状态监督员

 ● supervisor.service - LSB: Start/stop supervisor Loaded: loaded (/etc/init.d/supervisor) Active: active (running) since Wed 2015-12-23 15:48:45 CST; 1h 31min ago Process: 305 ExecStart=/etc/init.d/supervisor start (code=exited, status=0/SUCCESS) CGroup: /system.slice/supervisor.service ├─399 /usr/bin/python /usr/bin/supervisord -c /etc/supervisor/supervisord.conf ├─489 python server.py --port=8003 ├─490 python server.py --port=8000 ├─491 python server.py --port=8002 └─492 python server.py --port=8001 

经过进一步调查,问题实际上是我的Python龙卷风服务器。 这是每个CPU分派一个进程,这使我在一个核心树莓派混淆,但无论如何。

所以,上面的命令的输出是有效的; 主pipe或Systemd没有“重复”。 这个问题更多地与pipe理者对这些过程的生命周期pipe理有关,即启动,停止,重新加载。

当我停止之前,分叉进程将保持活动状态,所以当我重新启动主pipe时,总共会有4 + 8 = 12个进程。

解决的办法是将这一行添加到我的/etc/supervisor/conf.d/tornado.conf

 stopasgroup=true 

文档读取的内容

如果为true,那么标志会导致主pipe将停止信号发送给整个进程组,并暗示killasgroup为真。 这对程序非常有用,例如debugging模式下的Flask,它不会将停止信号传播给他们的孩子,使他们成为孤儿。