I have this bash script running with supervisor
#!/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")
It runs just fine, but when I do supervisorctl stop all, even though program stops, the inotifywait process keeps running. Is there a way to kill the inotifywait once the bash script exits?
Edit 1 Supervisor config for this program is
[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
I think you are missing an option to propagate the kill signal to all the child processes when you do
supervisorctl stop all. Usually one has a parent process and children, when the parent getsSIGTERM/SIGINTit will/should have a coordinated way and should be the one in charge of sending signals or by other means shutting down the children.The
supervisordprovides just an option for that. From the official documentationThe
killasgroupkills all processes in the group when Supervisor resorts to sending aSIGKILL. The idea is that when the process is playing nicely, it should be allowed to handle stopping it's children on its own. But when it misbehaves and needs an option for force the whole process group to termination.Also remember propagating
SIGINT, though the default action is to terminate gracefully can be ignored by processes. If you are not worried too much about graceful termination of the script, you can passSIGKILLwhich is the equivalent of signal generated bykill -9in Linux.So the following options in your supervisor config file