I have a very complicated application, which has its init-script and main service runs as a daemon. I want to stop it fast and gracefully, so I used this in stop() function:
group_id=$(ps -o pgid= $(cat $pidfile))
if [ ! -z $group_id ]; then
kill -- -$group_id
success
fi
It sends terminate signal to all subprocessess/threads. But, what if some of them spawn new subprocess? It seems like these new subprocesses don't finish their job, but I need to. If I send terminate signal to parent daemon, all subprocessess finish their job successfully, but in shell it shows that service has been already stopped (look at my previous topic - How to make init script print "OK" only when all subprocesses are stopped?) Probably, I miss something very obvious, but still I don't know how to fix this with minimal efforts. Please, give some ideas at least.