使用supervisorctl stop不会杀死inotifywait

问题描述 投票:3回答:1

我有这个bash脚本与主管一起运行

#!/bin/bash
DIR="/home/files"
while read file; do
   IFS=', ' read -r -a array <<< "$file"
   echo "Time: ${array[0]}"
   echo "File: ${array[1]}"
   #... doing something with the file
done < <(inotifywait -m -r -e close_write  "$DIR" --timefmt "%d_%b_%Y" --format "%T %w%f")

它运行得很好,但是当我做supervisorctl stop all时,即使程序停止,inotifywait进程仍在运行。一旦bash脚本退出,有没有办法杀死inotifywait

编辑此程序的1个Supervisor配置

[program:watch]
command=/root/watch_data.sh
user=root
stderr_logfile=/var/log/supervisord/watch_cloud.log
stdout_logfile=/var/log/supervisord/watch_cloud.log
autorestart=true
stopsignal=INT
bash ubuntu supervisord inotifywait
1个回答
4
投票

当你做supervisorctl stop all时,我认为你错过了将kill信号传播到所有子进程的选项。通常一个人有父进程和孩子,当父母得到SIGTERM / SIGINT时,它将/应该有一个协调的方式,应该是负责发送信号的人或通过其他方式关闭孩子。

supervisord只提供了一个选项。来自official documentation

stopasgroup

如果为true,则该标志使主管将停止信号发送到整个进程组并暗示killasgroup为真。这对于诸如调试模式下的Flask之类的程序非常有用,它们不会将停止信号传播给它们的子节点,使它们成为孤立的。

killasgroup

如果是真的,当诉诸于发送SIGKILL到程序终止它时,将其发送到整个进程组,同时照顾它的子进程,这对于使用多处理的Python程序很有用。

当Supervisor转向发送killasgroup时,SIGKILL会杀死该组中的所有进程。这个想法是,当这个过程很好玩时,应该允许它自己处理它的孩子。但是当它行为不端并需要强制选择时,整个过程组才会终止。

还记得传播SIGINT,虽然默认操作是优雅地终止可以被进程忽略。如果你不太担心脚本的优雅终止,你可以传递SIGKILL,这相当于kill -9在Linux中生成的信号。

因此,您的超级用户配置文件中包含以下选项

[program:watch]
command=/root/watch_data.sh
user=root
stderr_logfile=/var/log/supervisord/watch_cloud.log
stdout_logfile=/var/log/supervisord/watch_cloud.log
stopasgroup=true
killasgroup=true
stopsignal=KILL
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.