annotate src/libervia.sh @ 547:dd43132684b9

browser_side: fixes bug at profile disconnection
author souliane <souliane@mailoo.org>
date Wed, 10 Sep 2014 15:50:42 +0200
parents 750db9ff8525
children 160b45937ed2
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"
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 `
434
d64b415c58ca server_side: fixes startup script (as it's done in sat)
souliane <souliane@mailoo.org>
parents: 418
diff changeset
53 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
54 LOG_FILE="$LOG_DIR$APP_NAME_FILE.log"
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
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
57 if [ $# -eq 1 ];then
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"
418
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
67 fi
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
68 fi
ec8775575886 misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents: 417
diff changeset
69
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
70
512
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
71 #Don't change the next lines
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
72 PLUGIN_OPTIONS="-d .."
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
73 AUTO_OPTIONS=""
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
74 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
75
512
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
76
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
77 MAIN_OPTIONS="-${DAEMON}o"
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
78
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
79 log_dir=`dirname "$LOG_FILE"`
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
80 if [ ! -d $log_dir ] ; then
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
81 mkdir $log_dir
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
82 fi
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff changeset
83
512
750db9ff8525 server side: launching script improvments:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
84 twistd $MAIN_OPTIONS $ADDITIONAL_OPTIONS $APP_NAME_FILE $PLUGIN_OPTIONS