# HG changeset patch # User souliane # Date 1395611089 -3600 # Node ID 3b30e9f83d8882168e3282bddd98a14c22cbc3cb # Parent cbf4122baae78857ad5be31971c430039362575b misc: sat stop would not kill all sat instances anymore diff -r cbf4122baae7 -r 3b30e9f83d88 src/sat.sh --- a/src/sat.sh Sun Mar 23 22:43:43 2014 +0100 +++ b/src/sat.sh Sun Mar 23 22:44:49 2014 +0100 @@ -1,21 +1,25 @@ #!/bin/sh -#if there is one argument which is "stop", then we kill SàT DEBUG="" -if [ $# -eq 1 ];then - if [ $1 = "stop" ];then - echo "Terminating Salut à Toi" - pkill -f "twistd.*/sat.tac" - exit 0 - fi - if [ $1 = "debug" ];then - echo "Launching SàT in debug mode" - DEBUG="--debug" - fi -fi +NAME="sat" +FULL_NAME="Salut à Toi" +PYTHON="python2" -NAME='sat' -PYTHON='python' +kill_process() { + # $1 is the file containing the PID to kill, $2 is the process name + if [ -f $1 ]; then + PID=`cat $1` + if ps -p $PID > /dev/null; then + echo "Terminating $2... " + kill -INT $PID + else + echo "No running process of ID $PID... removing PID file" + rm -f $1 + fi + else + echo "$2 is probably not running (PID file doesn't exist)" + fi +} #We use python to parse config files eval `"$PYTHON" << PYTHONEND @@ -28,9 +32,9 @@ try: config.read(Const.CONFIG_FILES) except: - print ("echo \"/!\\ Can't read main config ! Please check the syntax\";") - print ("exit 1") - sys.exit() + print ("echo \"/!\\ Can't read main config ! Please check the syntax\";") + print ("exit 1") + sys.exit() env=[] env.append("PID_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'pid_dir')),'')) @@ -42,6 +46,19 @@ PID_FILE="$PID_DIR$NAME.pid" LOG_FILE="$LOG_DIR$NAME.log" + +# if there is one argument which is "stop", then we kill SàT +if [ $# -eq 1 ];then + if [ $1 = "stop" ];then + kill_process $PID_FILE "$FULL_NAME" + exit 0 + fi + if [ $1 = "debug" ];then + echo "Launching $FULL_NAME in debug mode" + DEBUG="--debug" + fi +fi + DAEMON="n" MAIN_OPTIONS="-${DAEMON}oy" TAP_PATH="./" @@ -53,7 +70,7 @@ log_dir=`dirname "$LOG_FILE"` if [ ! -d $log_dir ] ; then - mkdir $log_dir + mkdir $log_dir fi twistd $MAIN_OPTIONS $TAP_PATH$TAP_FILE $ADDITIONAL_OPTIONS