annotate bin/sat @ 3042:964abd07dc03

bridge (dbus): AsyncIO version of D-Bus bridge: The frontends D-Bus bridge has now an AIOBridge version which can be instantiated to use asyncio (the loop must be managed by frontends).
author Goffi <goffi@goffi.org>
date Tue, 01 Oct 2019 22:49:10 +0200
parents ab2696e34d29
children 8b36e5c3f28f
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=""
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
5 PYTHON="python3"
2438
a34b4fca16e2 core (sat.sh): force python 2 to launch twistd, and avoid launching wrong version if twistd is installed for python 3 too
Goffi <goffi@goffi.org>
parents: 1878
diff changeset
6 TWISTD="$(which twistd)"
234
a7079e835432 added stop command in sat.sh launching script
Goffi <goffi@goffi.org>
parents: 226
diff changeset
7
931
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
8 kill_process() {
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
9 # $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
10 if [ -f $1 ]; then
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
11 PID=`cat $1`
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
12 if ps -p $PID > /dev/null; then
1878
7a07f232e7cb misc (sat.sh): exec + better stop:
Goffi <goffi@goffi.org>
parents: 1548
diff changeset
13 printf "Terminating $2... "
1548
61c03265e133 launching script: use SIGTERM instead of SIGINT with the “stop” command
Goffi <goffi@goffi.org>
parents: 1151
diff changeset
14 kill $PID
1878
7a07f232e7cb misc (sat.sh): exec + better stop:
Goffi <goffi@goffi.org>
parents: 1548
diff changeset
15 while ps -p $PID > /dev/null; do
7a07f232e7cb misc (sat.sh): exec + better stop:
Goffi <goffi@goffi.org>
parents: 1548
diff changeset
16 sleep 0.2
7a07f232e7cb misc (sat.sh): exec + better stop:
Goffi <goffi@goffi.org>
parents: 1548
diff changeset
17 done
7a07f232e7cb misc (sat.sh): exec + better stop:
Goffi <goffi@goffi.org>
parents: 1548
diff changeset
18 printf "OK\n"
931
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
19 else
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
20 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
21 rm -f $1
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
22 fi
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
23 else
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
24 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
25 fi
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
26 }
4
3c1cefd41186 added sat executable
Goffi <goffi@goffi.org>
parents:
diff changeset
27
369
e83d0c21d64d launching script now read config files
Goffi <goffi@goffi.org>
parents: 358
diff changeset
28 #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
29 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
30 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
31 from sat.memory.memory import fixLocalDir
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
32 from configparser import ConfigParser
369
e83d0c21d64d launching script now read config files
Goffi <goffi@goffi.org>
parents: 358
diff changeset
33 from os.path import expanduser, join
463
ac568832a71a fixed lauching script
Goffi <goffi@goffi.org>
parents: 369
diff changeset
34 import sys
369
e83d0c21d64d launching script now read config files
Goffi <goffi@goffi.org>
parents: 358
diff changeset
35
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
36 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
37
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
38 config = ConfigParser(defaults=C.DEFAULT_CONFIG)
369
e83d0c21d64d launching script now read config files
Goffi <goffi@goffi.org>
parents: 358
diff changeset
39 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
40 config.read(C.CONFIG_FILES)
369
e83d0c21d64d launching script now read config files
Goffi <goffi@goffi.org>
parents: 358
diff changeset
41 except:
931
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
42 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
43 print ("exit 1")
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
44 sys.exit()
463
ac568832a71a fixed lauching script
Goffi <goffi@goffi.org>
parents: 369
diff changeset
45
ac568832a71a fixed lauching script
Goffi <goffi@goffi.org>
parents: 369
diff changeset
46 env=[]
ac568832a71a fixed lauching script
Goffi <goffi@goffi.org>
parents: 369
diff changeset
47 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
48 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
49 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
50 env.append("APP_NAME_FILE='%s'" % C.APP_NAME_FILE)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
51 print (";".join(env))
369
e83d0c21d64d launching script now read config files
Goffi <goffi@goffi.org>
parents: 358
diff changeset
52 PYTHONEND
e83d0c21d64d launching script now read config files
Goffi <goffi@goffi.org>
parents: 358
diff changeset
53 `
1114
7293233970ab misc: stdout encoding management in python part of sat.sh
Goffi <goffi@goffi.org>
parents: 1003
diff changeset
54 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
55 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
56 LOG_FILE="$LOG_DIR$APP_NAME_FILE.log"
1151
02c26e6630d0 misc (launch script): added a "status" command
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
57 RUNNING_MSG="$APP_NAME is running"
02c26e6630d0 misc (launch script): added a "status" command
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
58 NOT_RUNNING_MSG="$APP_NAME is *NOT* running"
931
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
59
2562
26edcf3a30eb core, setup: huge cleaning:
Goffi <goffi@goffi.org>
parents: 2438
diff changeset
60 # if there is one argument which is "stop", then we kill SaT
931
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
61 if [ $# -eq 1 ];then
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
62 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
63 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
64 exit 0
1115
b56374a1f6d6 misc: daemon mode refactoring:
Goffi <goffi@goffi.org>
parents: 1114
diff changeset
65 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
66 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
67 DEBUG="--debug"
1115
b56374a1f6d6 misc: daemon mode refactoring:
Goffi <goffi@goffi.org>
parents: 1114
diff changeset
68 elif [ $1 = "fg" ];then
b56374a1f6d6 misc: daemon mode refactoring:
Goffi <goffi@goffi.org>
parents: 1114
diff changeset
69 echo "Launching $APP_NAME in foreground mode"
b56374a1f6d6 misc: daemon mode refactoring:
Goffi <goffi@goffi.org>
parents: 1114
diff changeset
70 DAEMON="n"
1151
02c26e6630d0 misc (launch script): added a "status" command
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
71 elif [ $1 = "status" ];then
02c26e6630d0 misc (launch script): added a "status" command
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
72 if [ -f $PID_FILE ]; then
02c26e6630d0 misc (launch script): added a "status" command
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
73 PID=`cat $PID_FILE`
02c26e6630d0 misc (launch script): added a "status" command
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
74 ps -p$PID 2>&1 > /dev/null
02c26e6630d0 misc (launch script): added a "status" command
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
75 if [ $? = 0 ];then
02c26e6630d0 misc (launch script): added a "status" command
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
76 echo "$RUNNING_MSG (pid: $PID)"
02c26e6630d0 misc (launch script): added a "status" command
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
77 exit 0
02c26e6630d0 misc (launch script): added a "status" command
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
78 else
02c26e6630d0 misc (launch script): added a "status" command
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
79 echo "$NOT_RUNNING_MSG, but a pid file is present (bad exit ?): $PID_FILE"
02c26e6630d0 misc (launch script): added a "status" command
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
80 exit 2
02c26e6630d0 misc (launch script): added a "status" command
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
81 fi
02c26e6630d0 misc (launch script): added a "status" command
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
82 else
02c26e6630d0 misc (launch script): added a "status" command
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
83 echo "$NOT_RUNNING_MSG"
02c26e6630d0 misc (launch script): added a "status" command
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
84 exit 1
02c26e6630d0 misc (launch script): added a "status" command
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
85 fi
02c26e6630d0 misc (launch script): added a "status" command
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
86 else
02c26e6630d0 misc (launch script): added a "status" command
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
87 echo "bad argument, please use one of (stop, debug, fg, status) or no argument"
02c26e6630d0 misc (launch script): added a "status" command
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
88 exit 1
931
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
89 fi
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
90 fi
3b30e9f83d88 misc: sat stop would not kill all sat instances anymore
souliane <souliane@mailoo.org>
parents: 930
diff changeset
91
1122
9ae01ccf89c1 core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents: 1115
diff changeset
92 MAIN_OPTIONS="-${DAEMON}o"
225
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
93
1122
9ae01ccf89c1 core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents: 1115
diff changeset
94 #Don't change the next lines
225
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
95 AUTO_OPTIONS=""
249
0ed5553b5313 added "debug" command to sat launcher script
Goffi <goffi@goffi.org>
parents: 234
diff changeset
96 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
97
226
d8bb72f00eec distutils install: fixed plugin import and log file path
Goffi <goffi@goffi.org>
parents: 225
diff changeset
98 log_dir=`dirname "$LOG_FILE"`
d8bb72f00eec distutils install: fixed plugin import and log file path
Goffi <goffi@goffi.org>
parents: 225
diff changeset
99 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
100 mkdir $log_dir
226
d8bb72f00eec distutils install: fixed plugin import and log file path
Goffi <goffi@goffi.org>
parents: 225
diff changeset
101 fi
d8bb72f00eec distutils install: fixed plugin import and log file path
Goffi <goffi@goffi.org>
parents: 225
diff changeset
102
2438
a34b4fca16e2 core (sat.sh): force python 2 to launch twistd, and avoid launching wrong version if twistd is installed for python 3 too
Goffi <goffi@goffi.org>
parents: 1878
diff changeset
103 exec $PYTHON $TWISTD $MAIN_OPTIONS $ADDITIONAL_OPTIONS $APP_NAME_FILE