annotate bin/libervia @ 1193:aee3d8fa679f

pages: fixed cached data when `url_cache` is used: `request.template_data` and `request.data` where cached using a shallow copy, causing trouble when a mutable object was used. This has been fixed by using a deepcopy, which should not be a resource issue as `request.data` and `request.template_data` should contain a few data in most cases.
author Goffi <goffi@goffi.org>
date Wed, 12 Jun 2019 20:05:45 +0200
parents 28e3eb3bb217
children b2d067339de3
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=""
418
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
5 PYTHON="python2"
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
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
28 from ConfigParser import SafeConfigParser
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
512
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
31 import codecs
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
32 import locale
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
33
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
34 sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
35
434
d64b415c58ca server_side: fixes startup script (as it's done in sat)
souliane <souliane@mailoo.org>
parents: 418
diff changeset
36 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
37
d64b415c58ca server_side: fixes startup script (as it's done in sat)
souliane <souliane@mailoo.org>
parents: 418
diff changeset
38 config = SafeConfigParser(defaults=C.DEFAULT_CONFIG)
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
39 try:
434
d64b415c58ca server_side: fixes startup script (as it's done in sat)
souliane <souliane@mailoo.org>
parents: 418
diff changeset
40 config.read(C.CONFIG_FILES)
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
41 except:
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
42 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
43 print ("exit 1")
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
44 sys.exit()
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
45
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
46 env=[]
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
47 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
48 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
49 env.append("APP_NAME='%s'" % C.APP_NAME)
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
50 env.append("APP_NAME_FILE='%s'" % C.APP_NAME_FILE)
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
51 print ";".join(env)
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
52 PYTHONEND
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
53 `
561
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
54 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
55 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
56 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
57 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
58 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
59
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
60 # 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
61 if [ $# -ge 1 ];then
418
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
62 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
63 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
64 exit 0
512
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
65 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
66 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
67 DEBUG="--debug"
512
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
68 elif [ $1 = "fg" ];then
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
69 echo "Launching $APP_NAME in foreground mode"
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
70 DAEMON="n"
561
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
71 elif [ $1 = "status" ];then
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
72 if [ -f $PID_FILE ]; then
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
73 PID=`cat $PID_FILE`
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
74 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
75 if [ $? = 0 ];then
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
76 echo "$RUNNING_MSG (pid: $PID)"
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
77 exit 0
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, 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
80 exit 2
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 "$NOT_RUNNING_MSG"
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
84 exit 1
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
85 fi
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
86 else
160b45937ed2 misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents: 512
diff changeset
87 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
88 exit 1
418
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
89 fi
569
fb81aeccde8b restored commit 0090285a5689: the fix was actualy good, my bad
Goffi <goffi@goffi.org>
parents: 568
diff changeset
90 shift
418
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
91 fi
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
92
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
93
512
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
94 #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
95 PLUGIN_OPTIONS=""
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
96 AUTO_OPTIONS=""
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
97 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
98
512
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
99
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
100 MAIN_OPTIONS="-${DAEMON}o"
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
101
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
102 log_dir=`dirname "$LOG_FILE"`
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
103 if [ ! -d $log_dir ] ; then
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
104 mkdir $log_dir
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
105 fi
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
106
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
107 exec $PYTHON $TWISTD $MAIN_OPTIONS $ADDITIONAL_OPTIONS $APP_NAME_FILE $PLUGIN_OPTIONS $@