主管停止子进程

发布于 2025-01-01 20:46:01 字数 630 浏览 1 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

风铃鹿 2025-01-08 20:46:01

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

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

该示例如下:

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

另外,请记住,您可能有一个较旧的supervisord 包,它不具有“stopasgroup”功能。
我在 Raspberry Pi 上尝试了这些 Debian 软件包:

  • supervisor_3.0a8 不起作用。
  • Supervisor_3.0b2-1 按预期工作。

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:

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

  • supervisor_3.0a8 does not work.
  • supervisor_3.0b2-1 works as expected.
冰雪之触 2025-01-08 20:46:01

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

trap "kill -- -$" EXIT

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

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

trap "kill -- -$" EXIT

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

长发绾君心 2025-01-08 20:46:01

尝试这个主管程序配置:

stopasgroup=true
killasgroup=true
stopsignal=INT

try this supervisor program config:

stopasgroup=true
killasgroup=true
stopsignal=INT
爱人如己 2025-01-08 20:46:01

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

流绪微梦 2025-01-08 20:46:01

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

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

素食主义者 2025-01-08 20:46:01

您还可以在 /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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文