Hi,
I'm wanting to get a 'stop' (or similar) signal when the system is shutting down, so I can close my program down nicely.
I've setup a script and added it using 'chkconfig', it has both 'start' and 'stop' clauses, but it never receives a termination signal, only ever a 'start' argument. In my script this is part of what I use to govern runlevels:
# chkconfig: 2345 84 04
How, How, How?
Just for fun, here's the script. The logging is temp!:
Code:
#!/bin/bash
#
# Init file for usbtest server daemon
#
# chkconfig: 2345 84 04
# description: usbtest tester
#
dir="/home/ai/z_pylib/rck8055/usbtester_01"
script="main.py"
sname="usbtest"
logdir="/home/ai/z_pylib/rck8055/usbtester_01/log_01.txt"
echo 'CALLED:' $1 >> $logdir
case "$1" in
start)
cd $dir
nohup screen -dmS $sname python $script
echo 'START:' $1 >> $logdir
;;
stop)
process=`ps ax | grep $script | grep -v grep | grep -v SCREEN | awk '{print $1}'`
kill -s SIGINT $process
sleep 3
echo 'STOP:' $1 >> $logdir
exit
;;
attach)
screen -r $sname
echo 'ATTACH:' $1 >> $logdir
esac
exit
P.S. The program i'm running is in python and catches the 'stop' functions with the 'SystemExit' exception, when invoked manually.
Cheers!