主管停止子进程
我在 Supervisord 中面临的问题之一是,当我有一个命令又生成另一个进程时,supervisord 无法杀死它。
例如,我有一个 java 进程,正常运行时类似于
$ zkServer.sh start-foreground
$ ps -eaf | grep zk
user 30404 28280 0 09:21 pts/2 00:00:00 bash zkServer.sh start-foreground
user 30413 30404 76 09:21 pts/2 00:00:10 java -Dzookeeper.something..something
Supervisord 配置文件如下所示:
[program:zookeeper]
command=zkServer.sh start-foreground
autorestart=true
stopsignal=KILL
Supervisord 在从 supervisorctl
停止它们时,无法很好地处理具有多个子进程的此类进程。因此,当我从supervisord运行它并尝试从supervisorctl停止它时,只有顶层进程被杀死,而不是实际的java进程。
One of the problems, I face with supervisord is that when I have a command which in turn spawns another process, supervisord is not able to kill it.
For example I have a java process which when runs normally is like
$ zkServer.sh start-foreground
$ ps -eaf | grep zk
user 30404 28280 0 09:21 pts/2 00:00:00 bash zkServer.sh start-foreground
user 30413 30404 76 09:21 pts/2 00:00:10 java -Dzookeeper.something..something
The supervisord config file looks like:
[program:zookeeper]
command=zkServer.sh start-foreground
autorestart=true
stopsignal=KILL
These kind of processes which have multiple childs are not well handled by supervisord when it comes to stopping them from supervisorctl
. So when I run this from the supervisord and try to stop it from supervisorctl, only the top level process gets killed but not the actual java process.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
Rick Hanlon II 在这里遇到了同样的问题:https://coderwall.com/p/4tcw7w
选项stopasgroup= true 应该在程序部分设置,以便supervisord不仅停止父进程,还停止子进程。
该示例如下:
另外,请记住,您可能有一个较旧的supervisord 包,它不具有“stopasgroup”功能。
我在 Raspberry Pi 上尝试了这些 Debian 软件包:
The same problem was encountered by Rick Hanlon II here: https://coderwall.com/p/4tcw7w
Option stopasgroup=true should be set in the program section for supervisord to stop not only the parent process but also the child processes.
The example is given as:
Also, have in mind that you may have an older package of supervisord that does not have "stopasgroup" functionality.
I tried these Debian packages on Raspberry Pi:
在由supervisord调用的主bash脚本中尽早执行以下操作解决了我的问题:
当主脚本退出时,例如当它被supervisord杀死时,这会杀死整个进程组。
Doing the following early in the main bash script called by supervisord fixed the problem for me:
This kills the entire process group when the main script exits, such as when it is killed by supervisord.
尝试这个主管程序配置:
try this supervisor program config:
Supervisord 最近添加了一项功能,可以将 SIGKILL 发送到整个进程组。它位于 github 中,但尚未正式发布。
如果进程 ID 在文件中可用,则可以使用 pid-proxy 程序
A feature was recently added to supervisord to send SIGKILL to the whole process group. It's in github but not officially released yet.
If the process id is available in a file, you can use the pid-proxy program
以下文章对该问题进行了深入讨论:
http:// veithen.github.io/2014/11/16/sigterm-propagation.html
The following article has an in-depth discussion of the problem:
http://veithen.github.io/2014/11/16/sigterm-propagation.html
您还可以在
/conf.d/your-configuration.conf
文件中使用优先级。例如,如果您想先运行zookeeper,然后运行kafka,则可以指定两个程序。较低优先级意味着程序首先启动并最后停止。
You can also use priorities in
/conf.d/your-configuration.conf
file. For example, if you want to run zookeeper first and then kafka you can specify two programs.Lower priority means that the program starts first and stops last.