Mercurial > libervia-web
annotate libervia_server/libervia.sh @ 431:4fcf9bac109c
browser_side: roster management menus are now imported from the backend
author | souliane <souliane@mailoo.org> |
---|---|
date | Mon, 07 Apr 2014 23:31:21 +0200 |
parents | ec8775575886 |
children | d64b415c58ca |
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="" |
418
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
4 NAME="libervia" |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
5 FULL_NAME="Libervia" |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
6 PYTHON="python2" |
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 |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
13 echo "Terminating $2" |
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 |
417
2bd609d7dd65
server_side: use XDG recommended paths as the defaults
souliane <souliane@mailoo.org>
parents:
360
diff
changeset
|
26 from sat.core.constants import Const |
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 |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
30 |
417
2bd609d7dd65
server_side: use XDG recommended paths as the defaults
souliane <souliane@mailoo.org>
parents:
360
diff
changeset
|
31 config = SafeConfigParser(defaults=Const.DEFAULT_CONFIG) |
360
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
32 try: |
417
2bd609d7dd65
server_side: use XDG recommended paths as the defaults
souliane <souliane@mailoo.org>
parents:
360
diff
changeset
|
33 config.read(Const.CONFIG_FILES) |
360
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
34 except: |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
35 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
|
36 print ("exit 1") |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
37 sys.exit() |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
38 |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
39 env=[] |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
40 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
|
41 env.append("LOG_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'log_dir')),'')) |
360
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
42 |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
43 print ";".join(env) |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
44 PYTHONEND |
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 |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
47 PID_FILE="$PID_DIR$NAME.pid" |
417
2bd609d7dd65
server_side: use XDG recommended paths as the defaults
souliane <souliane@mailoo.org>
parents:
360
diff
changeset
|
48 LOG_FILE="$LOG_DIR$NAME.log" |
418
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
49 |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
50 # 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
|
51 if [ $# -eq 1 ];then |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
52 if [ $1 = "stop" ];then |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
53 kill_process $PID_FILE "$FULL_NAME" |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
54 exit 0 |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
55 fi |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
56 if [ $1 = "debug" ];then |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
57 echo "Launching $FULL_NAME in debug mode" |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
58 DEBUG="--debug" |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
59 fi |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
60 fi |
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
61 |
360
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
62 DAEMON="n" |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
63 MAIN_OPTIONS="-${DAEMON}o" |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
64 |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
65 #Don't change the next line |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
66 AUTO_OPTIONS="" |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
67 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
|
68 |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
69 log_dir=`dirname "$LOG_FILE"` |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
70 if [ ! -d $log_dir ] ; then |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
71 mkdir $log_dir |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
72 fi |
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
73 |
418
ec8775575886
misc: libervia stop would not kill all libervia instances anymore
souliane <souliane@mailoo.org>
parents:
417
diff
changeset
|
74 echo "Starting $FULL_NAME..." |
360
9834136b15ed
added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
75 twistd $MAIN_OPTIONS $ADDITIONAL_OPTIONS $NAME |