Mercurial > libervia-backend
comparison src/sat.sh @ 931:3b30e9f83d88
misc: sat stop would not kill all sat instances anymore
author | souliane <souliane@mailoo.org> |
---|---|
date | Sun, 23 Mar 2014 22:44:49 +0100 |
parents | cbf4122baae7 |
children | 52ec79aa5bbe |
comparison
equal
deleted
inserted
replaced
930:cbf4122baae7 | 931:3b30e9f83d88 |
---|---|
1 #!/bin/sh | 1 #!/bin/sh |
2 | 2 |
3 #if there is one argument which is "stop", then we kill SàT | |
4 DEBUG="" | 3 DEBUG="" |
5 if [ $# -eq 1 ];then | 4 NAME="sat" |
6 if [ $1 = "stop" ];then | 5 FULL_NAME="Salut à Toi" |
7 echo "Terminating Salut à Toi" | 6 PYTHON="python2" |
8 pkill -f "twistd.*/sat.tac" | |
9 exit 0 | |
10 fi | |
11 if [ $1 = "debug" ];then | |
12 echo "Launching SàT in debug mode" | |
13 DEBUG="--debug" | |
14 fi | |
15 fi | |
16 | 7 |
17 NAME='sat' | 8 kill_process() { |
18 PYTHON='python' | 9 # $1 is the file containing the PID to kill, $2 is the process name |
10 if [ -f $1 ]; then | |
11 PID=`cat $1` | |
12 if ps -p $PID > /dev/null; then | |
13 echo "Terminating $2... " | |
14 kill -INT $PID | |
15 else | |
16 echo "No running process of ID $PID... removing PID file" | |
17 rm -f $1 | |
18 fi | |
19 else | |
20 echo "$2 is probably not running (PID file doesn't exist)" | |
21 fi | |
22 } | |
19 | 23 |
20 #We use python to parse config files | 24 #We use python to parse config files |
21 eval `"$PYTHON" << PYTHONEND | 25 eval `"$PYTHON" << PYTHONEND |
22 from sat.core.constants import Const | 26 from sat.core.constants import Const |
23 from ConfigParser import SafeConfigParser | 27 from ConfigParser import SafeConfigParser |
26 | 30 |
27 config = SafeConfigParser(defaults=Const.DEFAULT_CONFIG) | 31 config = SafeConfigParser(defaults=Const.DEFAULT_CONFIG) |
28 try: | 32 try: |
29 config.read(Const.CONFIG_FILES) | 33 config.read(Const.CONFIG_FILES) |
30 except: | 34 except: |
31 print ("echo \"/!\\ Can't read main config ! Please check the syntax\";") | 35 print ("echo \"/!\\ Can't read main config ! Please check the syntax\";") |
32 print ("exit 1") | 36 print ("exit 1") |
33 sys.exit() | 37 sys.exit() |
34 | 38 |
35 env=[] | 39 env=[] |
36 env.append("PID_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'pid_dir')),'')) | 40 env.append("PID_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'pid_dir')),'')) |
37 env.append("LOG_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'log_dir')),'')) | 41 env.append("LOG_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'log_dir')),'')) |
38 | 42 |
40 PYTHONEND | 44 PYTHONEND |
41 ` | 45 ` |
42 | 46 |
43 PID_FILE="$PID_DIR$NAME.pid" | 47 PID_FILE="$PID_DIR$NAME.pid" |
44 LOG_FILE="$LOG_DIR$NAME.log" | 48 LOG_FILE="$LOG_DIR$NAME.log" |
49 | |
50 # if there is one argument which is "stop", then we kill SàT | |
51 if [ $# -eq 1 ];then | |
52 if [ $1 = "stop" ];then | |
53 kill_process $PID_FILE "$FULL_NAME" | |
54 exit 0 | |
55 fi | |
56 if [ $1 = "debug" ];then | |
57 echo "Launching $FULL_NAME in debug mode" | |
58 DEBUG="--debug" | |
59 fi | |
60 fi | |
61 | |
45 DAEMON="n" | 62 DAEMON="n" |
46 MAIN_OPTIONS="-${DAEMON}oy" | 63 MAIN_OPTIONS="-${DAEMON}oy" |
47 TAP_PATH="./" | 64 TAP_PATH="./" |
48 TAP_FILE="$NAME.tac" | 65 TAP_FILE="$NAME.tac" |
49 | 66 |
51 AUTO_OPTIONS="" | 68 AUTO_OPTIONS="" |
52 ADDITIONAL_OPTIONS="--pidfile $PID_FILE --logfile $LOG_FILE $AUTO_OPTIONS $DEBUG" | 69 ADDITIONAL_OPTIONS="--pidfile $PID_FILE --logfile $LOG_FILE $AUTO_OPTIONS $DEBUG" |
53 | 70 |
54 log_dir=`dirname "$LOG_FILE"` | 71 log_dir=`dirname "$LOG_FILE"` |
55 if [ ! -d $log_dir ] ; then | 72 if [ ! -d $log_dir ] ; then |
56 mkdir $log_dir | 73 mkdir $log_dir |
57 fi | 74 fi |
58 | 75 |
59 twistd $MAIN_OPTIONS $TAP_PATH$TAP_FILE $ADDITIONAL_OPTIONS | 76 twistd $MAIN_OPTIONS $TAP_PATH$TAP_FILE $ADDITIONAL_OPTIONS |