Mercurial > libervia-web
annotate bin/libervia @ 1216:b2d067339de3
python 3 port:
/!\ Python 3.6+ is now needed to use libervia
/!\ instability may occur and features may not be working anymore, this will improve with time
/!\ TxJSONRPC dependency has been removed
The same procedure as in backend has been applied (check backend commit ab2696e34d29 logs
for details). Removed now deprecated code (Pyjamas compiled browser part, legacy blog,
JSON RPC related code).
Adapted code to work without `html` and `themes` dirs.
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 13 Aug 2019 19:12:31 +0200 |
parents | 28e3eb3bb217 |
children | 63f7a2bd1d4a |
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 | 5 PYTHON="python3" |
983
8c9fdb58de5f
server (libervia.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:
877
diff
changeset
|
6 TWISTD="$(which twistd)" |
418
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
7 |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
8 kill_process() { |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
9 # $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
|
10 if [ -f $1 ]; then |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
11 PID=`cat $1` |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
12 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
|
13 echo "Terminating $2... " |
418
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
14 kill -INT $PID |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
15 else |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
16 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
|
17 rm -f $1 |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
18 fi |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
19 else |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
20 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
|
21 fi |
418
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
22 } |
360
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
23 |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
24 #We use python to parse config files |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
25 eval `"$PYTHON" << PYTHONEND |
512
750db9ff8525
server side: launching script improvments:
Goffi <goffi@goffi.org>
parents:
449
diff
changeset
|
26 from libervia.server.constants import Const as C |
434
d64b415c58ca
server_side: fixes startup script (as it's done in sat)
souliane <souliane@mailoo.org>
parents:
418
diff
changeset
|
27 from sat.memory.memory import fixLocalDir |
1216 | 28 from configparser import ConfigParser |
360
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
29 from os.path import expanduser, join |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
30 import sys |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
31 |
434
d64b415c58ca
server_side: fixes startup script (as it's done in sat)
souliane <souliane@mailoo.org>
parents:
418
diff
changeset
|
32 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
|
33 |
1216 | 34 config = ConfigParser(defaults=C.DEFAULT_CONFIG) |
360
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
35 try: |
434
d64b415c58ca
server_side: fixes startup script (as it's done in sat)
souliane <souliane@mailoo.org>
parents:
418
diff
changeset
|
36 config.read(C.CONFIG_FILES) |
360
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
37 except: |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
38 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
|
39 print ("exit 1") |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
40 sys.exit() |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
41 |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
42 env=[] |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
43 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
|
44 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
|
45 env.append("APP_NAME='%s'" % C.APP_NAME) |
750db9ff8525
server side: launching script improvments:
Goffi <goffi@goffi.org>
parents:
449
diff
changeset
|
46 env.append("APP_NAME_FILE='%s'" % C.APP_NAME_FILE) |
1216 | 47 print (";".join(env)) |
360
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
48 PYTHONEND |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
49 ` |
561
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
56 # 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
|
57 if [ $# -ge 1 ];then |
418
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
58 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
|
59 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
|
60 exit 0 |
512
750db9ff8525
server side: launching script improvments:
Goffi <goffi@goffi.org>
parents:
449
diff
changeset
|
61 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
|
62 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
|
63 DEBUG="--debug" |
512
750db9ff8525
server side: launching script improvments:
Goffi <goffi@goffi.org>
parents:
449
diff
changeset
|
64 elif [ $1 = "fg" ];then |
750db9ff8525
server side: launching script improvments:
Goffi <goffi@goffi.org>
parents:
449
diff
changeset
|
65 echo "Launching $APP_NAME in foreground mode" |
750db9ff8525
server side: launching script improvments:
Goffi <goffi@goffi.org>
parents:
449
diff
changeset
|
66 DAEMON="n" |
561
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
67 elif [ $1 = "status" ];then |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
68 if [ -f $PID_FILE ]; then |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
69 PID=`cat $PID_FILE` |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
70 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
|
71 if [ $? = 0 ];then |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
72 echo "$RUNNING_MSG (pid: $PID)" |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
73 exit 0 |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
74 else |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
75 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
|
76 exit 2 |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
77 fi |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
78 else |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
79 echo "$NOT_RUNNING_MSG" |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
80 exit 1 |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
81 fi |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
82 else |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
83 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
|
84 exit 1 |
418
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
85 fi |
569
fb81aeccde8b
restored commit 0090285a5689: the fix was actualy good, my bad
Goffi <goffi@goffi.org>
parents:
568
diff
changeset
|
86 shift |
418
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
87 fi |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
88 |
360
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
89 |
512
750db9ff8525
server side: launching script improvments:
Goffi <goffi@goffi.org>
parents:
449
diff
changeset
|
90 #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
|
91 PLUGIN_OPTIONS="" |
360
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
92 AUTO_OPTIONS="" |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
93 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
|
94 |
512
750db9ff8525
server side: launching script improvments:
Goffi <goffi@goffi.org>
parents:
449
diff
changeset
|
95 |
750db9ff8525
server side: launching script improvments:
Goffi <goffi@goffi.org>
parents:
449
diff
changeset
|
96 MAIN_OPTIONS="-${DAEMON}o" |
750db9ff8525
server side: launching script improvments:
Goffi <goffi@goffi.org>
parents:
449
diff
changeset
|
97 |
360
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
98 log_dir=`dirname "$LOG_FILE"` |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
99 if [ ! -d $log_dir ] ; then |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
100 mkdir $log_dir |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
101 fi |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
102 |
983
8c9fdb58de5f
server (libervia.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:
877
diff
changeset
|
103 exec $PYTHON $TWISTD $MAIN_OPTIONS $ADDITIONAL_OPTIONS $APP_NAME_FILE $PLUGIN_OPTIONS $@ |