annotate bin/libervia @ 1235:40c13ba6ba94

server: remove "launching" while logging version
author Goffi <goffi@goffi.org>
date Fri, 10 Jan 2020 10:09:18 +0100
parents b9a8049ca1ff
children 2ed4e399e1d4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
1 #!/bin/sh
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
2
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
3 DEBUG=""
512
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
4 DAEMON=""
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
5 PYTHON="python3"
1231
b9a8049ca1ff bin (libervia): look for twistd3 first:
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
6
b9a8049ca1ff bin (libervia): look for twistd3 first:
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
7 # for Python 3, "twistd" is named "twistd3" on some distros, so we check for it first
b9a8049ca1ff bin (libervia): look for twistd3 first:
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
8 TWISTD="$(which twistd3 2>/dev/null)"
b9a8049ca1ff bin (libervia): look for twistd3 first:
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
9 if [ $? -ne 0 ]; then
b9a8049ca1ff bin (libervia): look for twistd3 first:
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
10 TWISTD="$(which twistd 2>/dev/null)"
b9a8049ca1ff bin (libervia): look for twistd3 first:
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
11 fi
b9a8049ca1ff bin (libervia): look for twistd3 first:
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
12 if [ $? -ne 0 ]; then
b9a8049ca1ff bin (libervia): look for twistd3 first:
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
13 printf "Can't find \"twistd\" script, are you sure that Twisted is installed?\n"
b9a8049ca1ff bin (libervia): look for twistd3 first:
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
14 exit 1
b9a8049ca1ff bin (libervia): look for twistd3 first:
Goffi <goffi@goffi.org>
parents: 1225
diff changeset
15 fi
418
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
16
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
17 kill_process() {
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
18 # $1 is the file containing the PID to kill, $2 is the process name
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
19 if [ -f $1 ]; then
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
20 PID=`cat $1`
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
21 if ps -p $PID > /dev/null; then
434
d64b415c58ca server_side: fixes startup script (as it's done in sat)
souliane <souliane@mailoo.org>
parents: 418
diff changeset
22 echo "Terminating $2... "
418
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
23 kill -INT $PID
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
24 else
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
25 echo "No running process of ID $PID... removing PID file"
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
26 rm -f $1
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
27 fi
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
28 else
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
29 echo "$2 is probably not running (PID file doesn't exist)"
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
30 fi
418
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
31 }
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
32
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
33 #We use python to parse config files
1225
63f7a2bd1d4a misc: use /usr/bin/env + fixed import of fixLocalDir according to backend changes
Goffi <goffi@goffi.org>
parents: 1216
diff changeset
34 eval `/usr/bin/env "$PYTHON" << PYTHONEND
512
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
35 from libervia.server.constants import Const as C
1225
63f7a2bd1d4a misc: use /usr/bin/env + fixed import of fixLocalDir according to backend changes
Goffi <goffi@goffi.org>
parents: 1216
diff changeset
36 from sat.tools.config import fixLocalDir
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
37 from configparser import ConfigParser
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
38 from os.path import expanduser, join
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
39 import sys
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
40
434
d64b415c58ca server_side: fixes startup script (as it's done in sat)
souliane <souliane@mailoo.org>
parents: 418
diff changeset
41 fixLocalDir() # XXX: tmp update code, will be removed in the future
d64b415c58ca server_side: fixes startup script (as it's done in sat)
souliane <souliane@mailoo.org>
parents: 418
diff changeset
42
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
43 config = ConfigParser(defaults=C.DEFAULT_CONFIG)
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
44 try:
434
d64b415c58ca server_side: fixes startup script (as it's done in sat)
souliane <souliane@mailoo.org>
parents: 418
diff changeset
45 config.read(C.CONFIG_FILES)
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
46 except:
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
47 print ("echo \"/!\\ Can't read main config ! Please check the syntax\";")
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
48 print ("exit 1")
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
49 sys.exit()
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
50
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
51 env=[]
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
52 env.append("PID_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'pid_dir')),''))
417
2bd609d7dd65 server_side: use XDG recommended paths as the defaults
souliane <souliane@mailoo.org>
parents: 360
diff changeset
53 env.append("LOG_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'log_dir')),''))
512
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
54 env.append("APP_NAME='%s'" % C.APP_NAME)
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
55 env.append("APP_NAME_FILE='%s'" % C.APP_NAME_FILE)
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
56 print (";".join(env))
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
57 PYTHONEND
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
58 `
561
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
59 APP_NAME="$APP_NAME"
434
d64b415c58ca server_side: fixes startup script (as it's done in sat)
souliane <souliane@mailoo.org>
parents: 418
diff changeset
60 PID_FILE="$PID_DIR$APP_NAME_FILE.pid"
d64b415c58ca server_side: fixes startup script (as it's done in sat)
souliane <souliane@mailoo.org>
parents: 418
diff changeset
61 LOG_FILE="$LOG_DIR$APP_NAME_FILE.log"
561
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
62 RUNNING_MSG="$APP_NAME is running"
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
63 NOT_RUNNING_MSG="$APP_NAME is *NOT* running"
418
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
64
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
65 # if there is one argument which is "stop", then we kill Libervia
562
7e8356479fef misc: launch script fix (there can now be more than 1 argument)
Goffi <goffi@goffi.org>
parents: 561
diff changeset
66 if [ $# -ge 1 ];then
418
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
67 if [ $1 = "stop" ];then
434
d64b415c58ca server_side: fixes startup script (as it's done in sat)
souliane <souliane@mailoo.org>
parents: 418
diff changeset
68 kill_process $PID_FILE "$APP_NAME"
418
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
69 exit 0
512
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
70 elif [ $1 = "debug" ];then
434
d64b415c58ca server_side: fixes startup script (as it's done in sat)
souliane <souliane@mailoo.org>
parents: 418
diff changeset
71 echo "Launching $APP_NAME in debug mode"
418
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
72 DEBUG="--debug"
512
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
73 elif [ $1 = "fg" ];then
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
74 echo "Launching $APP_NAME in foreground mode"
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
75 DAEMON="n"
561
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
76 elif [ $1 = "status" ];then
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
77 if [ -f $PID_FILE ]; then
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
78 PID=`cat $PID_FILE`
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
79 ps -p$PID 2>&1 > /dev/null
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
80 if [ $? = 0 ];then
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
81 echo "$RUNNING_MSG (pid: $PID)"
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
82 exit 0
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
83 else
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
84 echo "$NOT_RUNNING_MSG, but a pid file is present (bad exit ?): $PID_FILE"
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
85 exit 2
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
86 fi
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
87 else
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
88 echo "$NOT_RUNNING_MSG"
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
89 exit 1
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
90 fi
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
91 else
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
92 echo "bad argument, please use one of (stop, debug, fg, status) or no argument"
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
93 exit 1
418
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
94 fi
569
fb81aeccde8b restored commit 0090285a5689: the fix was actualy good, my bad
Goffi <goffi@goffi.org>
parents: 568
diff changeset
95 shift
418
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
96 fi
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
97
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
98
512
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
99 #Don't change the next lines
1103
a6bef71a7fd0 misc (libervia.sh): removed "-d .." from PLUGIN_OPTIONS as it was overriding sat.conf in some cases
Goffi <goffi@goffi.org>
parents: 983
diff changeset
100 PLUGIN_OPTIONS=""
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
101 AUTO_OPTIONS=""
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
102 ADDITIONAL_OPTIONS="--pidfile $PID_FILE --logfile $LOG_FILE $AUTO_OPTIONS $DEBUG"
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
103
512
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
104
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
105 MAIN_OPTIONS="-${DAEMON}o"
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
106
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
107 log_dir=`dirname "$LOG_FILE"`
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
108 if [ ! -d $log_dir ] ; then
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
109 mkdir $log_dir
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
110 fi
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
111
1225
63f7a2bd1d4a misc: use /usr/bin/env + fixed import of fixLocalDir according to backend changes
Goffi <goffi@goffi.org>
parents: 1216
diff changeset
112 exec /usr/bin/env $PYTHON $TWISTD $MAIN_OPTIONS $ADDITIONAL_OPTIONS $APP_NAME_FILE $PLUGIN_OPTIONS $@