Mercurial > libervia-web
annotate src/libervia.sh @ 966:12c149171199
pages (data post): pages can now be redirected to a other uri than current page, using request.data['post_redirect_uri']
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 05 Nov 2017 20:32:29 +0100 |
parents | acde4b729034 |
children | 8c9fdb58de5f |
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" |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
6 |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
7 kill_process() { |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
8 # $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
|
9 if [ -f $1 ]; then |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
10 PID=`cat $1` |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
11 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
|
12 echo "Terminating $2... " |
418
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
13 kill -INT $PID |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
14 else |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
15 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
|
16 rm -f $1 |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
17 fi |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
18 else |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
19 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
|
20 fi |
418
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
21 } |
360
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
22 |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
23 #We use python to parse config files |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
24 eval `"$PYTHON" << PYTHONEND |
512
750db9ff8525
server side: launching script improvments:
Goffi <goffi@goffi.org>
parents:
449
diff
changeset
|
25 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
|
26 from sat.memory.memory import fixLocalDir |
360
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
27 from ConfigParser import SafeConfigParser |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
28 from os.path import expanduser, join |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
29 import sys |
512
750db9ff8525
server side: launching script improvments:
Goffi <goffi@goffi.org>
parents:
449
diff
changeset
|
30 import codecs |
750db9ff8525
server side: launching script improvments:
Goffi <goffi@goffi.org>
parents:
449
diff
changeset
|
31 import locale |
750db9ff8525
server side: launching script improvments:
Goffi <goffi@goffi.org>
parents:
449
diff
changeset
|
32 |
750db9ff8525
server side: launching script improvments:
Goffi <goffi@goffi.org>
parents:
449
diff
changeset
|
33 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
|
34 |
434
d64b415c58ca
server_side: fixes startup script (as it's done in sat)
souliane <souliane@mailoo.org>
parents:
418
diff
changeset
|
35 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
|
36 |
d64b415c58ca
server_side: fixes startup script (as it's done in sat)
souliane <souliane@mailoo.org>
parents:
418
diff
changeset
|
37 config = SafeConfigParser(defaults=C.DEFAULT_CONFIG) |
360
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
38 try: |
434
d64b415c58ca
server_side: fixes startup script (as it's done in sat)
souliane <souliane@mailoo.org>
parents:
418
diff
changeset
|
39 config.read(C.CONFIG_FILES) |
360
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
40 except: |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
41 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
|
42 print ("exit 1") |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
43 sys.exit() |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
44 |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
45 env=[] |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
46 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
|
47 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
|
48 env.append("APP_NAME='%s'" % C.APP_NAME) |
750db9ff8525
server side: launching script improvments:
Goffi <goffi@goffi.org>
parents:
449
diff
changeset
|
49 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
|
50 print ";".join(env) |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
51 PYTHONEND |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
52 ` |
561
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
53 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
59 # 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
|
60 if [ $# -ge 1 ];then |
418
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
61 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
|
62 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
|
63 exit 0 |
512
750db9ff8525
server side: launching script improvments:
Goffi <goffi@goffi.org>
parents:
449
diff
changeset
|
64 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
|
65 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
|
66 DEBUG="--debug" |
512
750db9ff8525
server side: launching script improvments:
Goffi <goffi@goffi.org>
parents:
449
diff
changeset
|
67 elif [ $1 = "fg" ];then |
750db9ff8525
server side: launching script improvments:
Goffi <goffi@goffi.org>
parents:
449
diff
changeset
|
68 echo "Launching $APP_NAME in foreground mode" |
750db9ff8525
server side: launching script improvments:
Goffi <goffi@goffi.org>
parents:
449
diff
changeset
|
69 DAEMON="n" |
561
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
70 elif [ $1 = "status" ];then |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
71 if [ -f $PID_FILE ]; then |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
72 PID=`cat $PID_FILE` |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
73 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
|
74 if [ $? = 0 ];then |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
75 echo "$RUNNING_MSG (pid: $PID)" |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
76 exit 0 |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
77 else |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
78 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
|
79 exit 2 |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
80 fi |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
81 else |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
82 echo "$NOT_RUNNING_MSG" |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
83 exit 1 |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
84 fi |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
85 else |
160b45937ed2
misc: launch script now manage "status" command, and additional arguments
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
86 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
|
87 exit 1 |
418
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
88 fi |
569
fb81aeccde8b
restored commit 0090285a5689: the fix was actualy good, my bad
Goffi <goffi@goffi.org>
parents:
568
diff
changeset
|
89 shift |
418
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
90 fi |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
91 |
360
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
92 |
512
750db9ff8525
server side: launching script improvments:
Goffi <goffi@goffi.org>
parents:
449
diff
changeset
|
93 #Don't change the next lines |
750db9ff8525
server side: launching script improvments:
Goffi <goffi@goffi.org>
parents:
449
diff
changeset
|
94 PLUGIN_OPTIONS="-d .." |
360
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
95 AUTO_OPTIONS="" |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
96 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
|
97 |
512
750db9ff8525
server side: launching script improvments:
Goffi <goffi@goffi.org>
parents:
449
diff
changeset
|
98 |
750db9ff8525
server side: launching script improvments:
Goffi <goffi@goffi.org>
parents:
449
diff
changeset
|
99 MAIN_OPTIONS="-${DAEMON}o" |
750db9ff8525
server side: launching script improvments:
Goffi <goffi@goffi.org>
parents:
449
diff
changeset
|
100 |
360
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
101 log_dir=`dirname "$LOG_FILE"` |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
102 if [ ! -d $log_dir ] ; then |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
103 mkdir $log_dir |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
104 fi |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
105 |
877
acde4b729034
added exec to launch twistd in libervia.sh, so twistd replace the script process, which is useful particularly in foreground mode (signals can be catched correclty for instance)
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
106 exec twistd $MAIN_OPTIONS $ADDITIONAL_OPTIONS $APP_NAME_FILE $PLUGIN_OPTIONS $@ |