Mercurial > libervia-web
comparison libervia_server/libervia.sh @ 434:d64b415c58ca
server_side: fixes startup script (as it's done in sat)
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 01 May 2014 11:34:36 +0200 |
parents | ec8775575886 |
children |
comparison
equal
deleted
inserted
replaced
433:bbdbee25123a | 434:d64b415c58ca |
---|---|
1 #!/bin/sh | 1 #!/bin/sh |
2 | 2 |
3 DEBUG="" | 3 DEBUG="" |
4 NAME="libervia" | |
5 FULL_NAME="Libervia" | |
6 PYTHON="python2" | 4 PYTHON="python2" |
7 | 5 |
8 kill_process() { | 6 kill_process() { |
9 # $1 is the file containing the PID to kill, $2 is the process name | 7 # $1 is the file containing the PID to kill, $2 is the process name |
10 if [ -f $1 ]; then | 8 if [ -f $1 ]; then |
11 PID=`cat $1` | 9 PID=`cat $1` |
12 if ps -p $PID > /dev/null; then | 10 if ps -p $PID > /dev/null; then |
13 echo "Terminating $2" | 11 echo "Terminating $2... " |
14 kill -INT $PID | 12 kill -INT $PID |
15 else | 13 else |
16 echo "No running process of ID $PID... removing PID file" | 14 echo "No running process of ID $PID... removing PID file" |
17 rm -f $1 | 15 rm -f $1 |
18 fi | 16 fi |
21 fi | 19 fi |
22 } | 20 } |
23 | 21 |
24 #We use python to parse config files | 22 #We use python to parse config files |
25 eval `"$PYTHON" << PYTHONEND | 23 eval `"$PYTHON" << PYTHONEND |
26 from sat.core.constants import Const | 24 |
25 from sat.core.constants import Const as C | |
26 from sat.memory.memory import fixLocalDir | |
27 from ConfigParser import SafeConfigParser | 27 from ConfigParser import SafeConfigParser |
28 from os.path import expanduser, join | 28 from os.path import expanduser, join |
29 import sys | 29 import sys |
30 | 30 |
31 config = SafeConfigParser(defaults=Const.DEFAULT_CONFIG) | 31 fixLocalDir() # XXX: tmp update code, will be removed in the future |
32 | |
33 config = SafeConfigParser(defaults=C.DEFAULT_CONFIG) | |
32 try: | 34 try: |
33 config.read(Const.CONFIG_FILES) | 35 config.read(C.CONFIG_FILES) |
34 except: | 36 except: |
35 print ("echo \"/!\\ Can't read main config ! Please check the syntax\";") | 37 print ("echo \"/!\\ Can't read main config ! Please check the syntax\";") |
36 print ("exit 1") | 38 print ("exit 1") |
37 sys.exit() | 39 sys.exit() |
38 | 40 |
39 env=[] | 41 env=[] |
40 env.append("PID_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'pid_dir')),'')) | 42 env.append("PID_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'pid_dir')),'')) |
41 env.append("LOG_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'log_dir')),'')) | 43 env.append("LOG_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'log_dir')),'')) |
42 | |
43 print ";".join(env) | 44 print ";".join(env) |
44 PYTHONEND | 45 PYTHONEND |
45 ` | 46 ` |
46 | 47 APP_NAME="Libervia" # FIXME: the import from Python needs libervia module to be in PYTHONPATH |
47 PID_FILE="$PID_DIR$NAME.pid" | 48 APP_NAME_FILE="libervia" |
48 LOG_FILE="$LOG_DIR$NAME.log" | 49 PID_FILE="$PID_DIR$APP_NAME_FILE.pid" |
50 LOG_FILE="$LOG_DIR$APP_NAME_FILE.log" | |
49 | 51 |
50 # if there is one argument which is "stop", then we kill Libervia | 52 # if there is one argument which is "stop", then we kill Libervia |
51 if [ $# -eq 1 ];then | 53 if [ $# -eq 1 ];then |
52 if [ $1 = "stop" ];then | 54 if [ $1 = "stop" ];then |
53 kill_process $PID_FILE "$FULL_NAME" | 55 kill_process $PID_FILE "$APP_NAME" |
54 exit 0 | 56 exit 0 |
55 fi | 57 fi |
56 if [ $1 = "debug" ];then | 58 if [ $1 = "debug" ];then |
57 echo "Launching $FULL_NAME in debug mode" | 59 echo "Launching $APP_NAME in debug mode" |
58 DEBUG="--debug" | 60 DEBUG="--debug" |
59 fi | 61 fi |
60 fi | 62 fi |
61 | 63 |
62 DAEMON="n" | 64 DAEMON="n" |
69 log_dir=`dirname "$LOG_FILE"` | 71 log_dir=`dirname "$LOG_FILE"` |
70 if [ ! -d $log_dir ] ; then | 72 if [ ! -d $log_dir ] ; then |
71 mkdir $log_dir | 73 mkdir $log_dir |
72 fi | 74 fi |
73 | 75 |
74 echo "Starting $FULL_NAME..." | 76 echo "Starting $APP_NAME..." |
75 twistd $MAIN_OPTIONS $ADDITIONAL_OPTIONS $NAME | 77 twistd $MAIN_OPTIONS $ADDITIONAL_OPTIONS $APP_NAME_FILE |