I have a script that will track a process and if that process dies, it will respawn it. I want the tracking script to also kill the process if told to do so by giving the tracking script a sigterm (for example.). In other words, if I kill the tracking script, it should also kill the process that it's tracking, not respawn anymore and exit.
Cobbling together several posts (which I think are the best practices, for instance don't use a PID file), I get the following:
#!/bin/bash
DESC="Foo Manager"
EXEC="python /myPath/bin/FooManager.pyc"
trap "BREAK=1;pkill -HUP -P $BASHPID;exit 0" SIGHUP SIGINT SIGTERM
until $EXEC
do
echo "Server $DESC crashed with exit code $?. Restarting..." >&2
((BREAK!=0)) && echo "Breaking" && exit 1
sleep 1
done
So, now if I run this script in one xterm. And then in another xterm I send the script something like:
kill -HUP <tracking_script_pid> # Doesn't work.
kill -TERM <tracking_script_pid> #Doesn't work.
The tracking script does not end or anything. If I run FooManager.pyc from the commandline, it will die on SIGHUP and SIGTERM. Anyways, what could I be doing wrong here, and perhaps there's a whole different way to do it?
thanks.