bash 主管停止子进程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9090683/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 21:36:53  来源:igfitidea点击:

supervisord stopping child processes

bashapache-zookeepersupervisordubuntu-11.04

提问by FUD

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.

我在使用 supervisord 时面临的一个问题是,当我有一个命令反过来产生另一个进程时,supervisord 无法杀死它。

For example I have a java process which when runs normally is like

例如,我有一个 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

The supervisord config file looks like:

supervisord 配置文件如下所示:

[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.

在阻止它们从supervisorctl. 因此,当我从 supervisord 运行它并尝试从 supervisorctl 中停止它时,只有顶级进程被杀死,而不是实际的 java 进程。

回答by kuzavas

The same problem was encountered by Rick Hanlon II here: https://coderwall.com/p/4tcw7w

Rick Hanlon II 在这里遇到了同样的问题:https: //coderwall.com/p/4tcw7w

Option stopasgroup=trueshould be set in the program section for supervisord to stop not only the parent process but also the child processes.

选项stopasgroup=true应该在程序部分设置为 supervisord 不仅停止父进程,而且停止子进程。

The example is given as:

示例如下:

[program:some_django]
 command=python manage.py runserver
 directory=/dir/to/app
 stopasgroup=true

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 包,它没有“stopasgroup”功能。我在 Raspberry Pi 上尝试了这些 Debian 软件包:

  • supervisor_3.0a8 does not work.
  • supervisor_3.0b2-1 works as expected.
  • supervisor_3.0a8 不起作用。
  • supervisor_3.0b2-1 按预期工作。

回答by Fred Yankowski

Doing the following early in the main bash script called by supervisord fixed the problem for me:

在由 supervisord 调用的主 bash 脚本早期执行以下操作为我解决了问题:

trap "kill -- -$$" EXIT

This kills the entire process group when the main script exits, such as when it is killed by supervisord.

这会在主脚本退出时杀死整个进程组,例如当它被 supervisord 杀死时。

回答by Roger Hoover

A feature was recently added to supervisord to send SIGKILL to the whole process group. It's in githubbut not officially released yet.

最近在 supervisord 中添加了一个功能,将 SIGKILL 发送到整个进程组。它在github 中,但尚未正式发布。

If the process id is available in a file, you can use the pid-proxy program

如果进程 id 在文件中可用,则可以使用pid-proxy 程序

回答by Andreas Veithen

The following article has an in-depth discussion of the problem:

以下文章对该问题进行了深入讨论:

http://veithen.github.io/2014/11/16/sigterm-propagation.html

http://veithen.github.io/2014/11/16/sigterm-propagation.html

回答by Color

try this supervisor program config:

试试这个主管程序配置:

stopasgroup=true
killasgroup=true
stopsignal=INT

回答by baqx0r

You can also use priorities in /conf.d/your-configuration.conffile. For example, if you want to run zookeeper first and then kafka you can specify two programs.

您还可以在/conf.d/your-configuration.conf文件中使用优先级。例如,如果您想先运行zookeeper,然后运行kafka,则可以指定两个程序。

Lower priority means that the program starts first and stops last.

较低的优先级意味着程序首先启动,最后停止。