annotate src/sat.sh @ 1122:9ae01ccf89c1

core: sat bakcend is now a twisted plugin (no more .tac file)
author Goffi <goffi@goffi.org>
date Sun, 24 Aug 2014 18:44:17 +0200
parents b56374a1f6d6
children 02c26e6630d0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
3c1cefd41186 added sat executable
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/bin/sh
225
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
2
249
0ed5553b5313 added "debug" command to sat launcher script
Goffi <goffi@goffi.org>
parents: 234
diff changeset
3 DEBUG=""
1115
b56374a1f6d6 misc: daemon mode refactoring:
Goffi <goffi@goffi.org>
parents: 1114
diff changeset
4 DAEMON=""
931
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
5 PYTHON="python2"
234
a7079e835432 added stop command in sat.sh launching script
Goffi <goffi@goffi.org>
parents: 226
diff changeset
6
931
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
7 kill_process() {
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
8 # $1 is the file containing the PID to kill, $2 is the process name
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
9 if [ -f $1 ]; then
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
10 PID=`cat $1`
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
11 if ps -p $PID > /dev/null; then
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
12 echo "Terminating $2... "
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
13 kill -INT $PID
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
14 else
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
15 echo "No running process of ID $PID... removing PID file"
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
16 rm -f $1
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
17 fi
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
18 else
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
19 echo "$2 is probably not running (PID file doesn't exist)"
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
20 fi
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
21 }
4
3c1cefd41186 added sat executable
Goffi <goffi@goffi.org>
parents:
diff changeset
22
369
e83d0c21d64d launching script now read config files
Goffi <goffi@goffi.org>
parents: 358
diff changeset
23 #We use python to parse config files
473
a11cde0cdf5b misc: Make the shell launcher use the same python interpreter than setup.py.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 463
diff changeset
24 eval `"$PYTHON" << PYTHONEND
1003
52ec79aa5bbe memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents: 931
diff changeset
25 from sat.core.constants import Const as C
52ec79aa5bbe memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents: 931
diff changeset
26 from sat.memory.memory import fixLocalDir
369
e83d0c21d64d launching script now read config files
Goffi <goffi@goffi.org>
parents: 358
diff changeset
27 from ConfigParser import SafeConfigParser
e83d0c21d64d launching script now read config files
Goffi <goffi@goffi.org>
parents: 358
diff changeset
28 from os.path import expanduser, join
463
ac568832a71a fixed lauching script
Goffi <goffi@goffi.org>
parents: 369
diff changeset
29 import sys
1114
7293233970ab misc: stdout encoding management in python part of sat.sh
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
30 import codecs
7293233970ab misc: stdout encoding management in python part of sat.sh
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
31 import locale
7293233970ab misc: stdout encoding management in python part of sat.sh
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
32
7293233970ab misc: stdout encoding management in python part of sat.sh
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
33 sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
369
e83d0c21d64d launching script now read config files
Goffi <goffi@goffi.org>
parents: 358
diff changeset
34
1003
52ec79aa5bbe memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents: 931
diff changeset
35 fixLocalDir() # XXX: tmp update code, will be removed in the future
52ec79aa5bbe memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents: 931
diff changeset
36
52ec79aa5bbe memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents: 931
diff changeset
37 config = SafeConfigParser(defaults=C.DEFAULT_CONFIG)
369
e83d0c21d64d launching script now read config files
Goffi <goffi@goffi.org>
parents: 358
diff changeset
38 try:
1003
52ec79aa5bbe memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents: 931
diff changeset
39 config.read(C.CONFIG_FILES)
369
e83d0c21d64d launching script now read config files
Goffi <goffi@goffi.org>
parents: 358
diff changeset
40 except:
931
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
41 print ("echo \"/!\\ Can't read main config ! Please check the syntax\";")
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
42 print ("exit 1")
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
43 sys.exit()
463
ac568832a71a fixed lauching script
Goffi <goffi@goffi.org>
parents: 369
diff changeset
44
ac568832a71a fixed lauching script
Goffi <goffi@goffi.org>
parents: 369
diff changeset
45 env=[]
ac568832a71a fixed lauching script
Goffi <goffi@goffi.org>
parents: 369
diff changeset
46 env.append("PID_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'pid_dir')),''))
930
cbf4122baae7 core, memory: use XDG recommended paths as the defaults for the config and local directories
souliane <souliane@mailoo.org>
parents: 587
diff changeset
47 env.append("LOG_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'log_dir')),''))
1114
7293233970ab misc: stdout encoding management in python part of sat.sh
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
48 env.append("APP_NAME='%s'" % C.APP_NAME)
1003
52ec79aa5bbe memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents: 931
diff changeset
49 env.append("APP_NAME_FILE='%s'" % C.APP_NAME_FILE)
463
ac568832a71a fixed lauching script
Goffi <goffi@goffi.org>
parents: 369
diff changeset
50 print ";".join(env)
369
e83d0c21d64d launching script now read config files
Goffi <goffi@goffi.org>
parents: 358
diff changeset
51 PYTHONEND
e83d0c21d64d launching script now read config files
Goffi <goffi@goffi.org>
parents: 358
diff changeset
52 `
1114
7293233970ab misc: stdout encoding management in python part of sat.sh
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
53 APP_NAME="$APP_NAME"
1003
52ec79aa5bbe memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents: 931
diff changeset
54 PID_FILE="$PID_DIR$APP_NAME_FILE.pid"
52ec79aa5bbe memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents: 931
diff changeset
55 LOG_FILE="$LOG_DIR$APP_NAME_FILE.log"
931
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
56
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
57 # if there is one argument which is "stop", then we kill SàT
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
58 if [ $# -eq 1 ];then
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
59 if [ $1 = "stop" ];then
1003
52ec79aa5bbe memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents: 931
diff changeset
60 kill_process $PID_FILE "$APP_NAME"
931
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
61 exit 0
1115
b56374a1f6d6 misc: daemon mode refactoring:
Goffi <goffi@goffi.org>
parents: 1114
diff changeset
62 elif [ $1 = "debug" ];then
1003
52ec79aa5bbe memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents: 931
diff changeset
63 echo "Launching $APP_NAME in debug mode"
931
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
64 DEBUG="--debug"
1115
b56374a1f6d6 misc: daemon mode refactoring:
Goffi <goffi@goffi.org>
parents: 1114
diff changeset
65 elif [ $1 = "fg" ];then
b56374a1f6d6 misc: daemon mode refactoring:
Goffi <goffi@goffi.org>
parents: 1114
diff changeset
66 echo "Launching $APP_NAME in foreground mode"
b56374a1f6d6 misc: daemon mode refactoring:
Goffi <goffi@goffi.org>
parents: 1114
diff changeset
67 DAEMON="n"
931
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
68 fi
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
69 fi
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
70
1122
9ae01ccf89c1 core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents: 1115
diff changeset
71 MAIN_OPTIONS="-${DAEMON}o"
225
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
72
1122
9ae01ccf89c1 core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents: 1115
diff changeset
73 #Don't change the next lines
225
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
74 AUTO_OPTIONS=""
249
0ed5553b5313 added "debug" command to sat launcher script
Goffi <goffi@goffi.org>
parents: 234
diff changeset
75 ADDITIONAL_OPTIONS="--pidfile $PID_FILE --logfile $LOG_FILE $AUTO_OPTIONS $DEBUG"
225
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
76
226
d8bb72f00eec distutils install: fixed plugin import and log file path
Goffi <goffi@goffi.org>
parents: 225
diff changeset
77 log_dir=`dirname "$LOG_FILE"`
d8bb72f00eec distutils install: fixed plugin import and log file path
Goffi <goffi@goffi.org>
parents: 225
diff changeset
78 if [ ! -d $log_dir ] ; then
931
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
79 mkdir $log_dir
226
d8bb72f00eec distutils install: fixed plugin import and log file path
Goffi <goffi@goffi.org>
parents: 225
diff changeset
80 fi
d8bb72f00eec distutils install: fixed plugin import and log file path
Goffi <goffi@goffi.org>
parents: 225
diff changeset
81
1122
9ae01ccf89c1 core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents: 1115
diff changeset
82 twistd $MAIN_OPTIONS $ADDITIONAL_OPTIONS $APP_NAME_FILE