I have a very complex python application. It has it's own init script, but when I execute:
sudo service my_service_daemon stop
It prints "Stopping my_service_daemon [OK]", but in real subprocesses still alive, until they finish their work (they caught signal 15, but have to finish some job). So, I want that message "[OK]" will be printed only when there are no subprocesses at all. Here is part of init script (it runs on CentOS 6)
...
. /etc/init.d/functions
...
stop(){
echo -n $"Stopping $prog: "
if [ -a $pidfile ]; then
group_id=$(ps -o pgid= $(cat $pidfile) | grep -o [0-9]*)
if [ ! -z $group_id ]; then
kill -- -$group_id
success
fi
else
failure
fi
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f $lockfile $pidfile
}
ps -o pid= --ppid $(cat $pidfile)
, maybe? – muru Oct 20 '15 at 17:55