Mercurial > libervia-web
comparison src/libervia.sh @ 512:750db9ff8525
server side: launching script improvments:
- no more difference between installed version and source version: libervia is a deamon by defaut, "fg" must be used to launch it foreground
- fixed bad constants module imported in python part of libervia.sh
- fixed stdout encoding in python part of libervia.sh
- APP_NAME and APP_NAME_FILE use the constants module values
- DATA_DIR variable moved to PLUGIN_OPTIONS
- (constants) ASCII_APP_NAME renamed to APP_NAME_FILE to be consistent with SàT backend.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 24 Aug 2014 18:43:45 +0200 |
parents | 981ed669d3b3 |
children | 160b45937ed2 |
comparison
equal
deleted
inserted
replaced
511:8843ae9e92bd | 512:750db9ff8525 |
---|---|
1 #!/bin/sh | 1 #!/bin/sh |
2 | 2 |
3 DEBUG="" | 3 DEBUG="" |
4 DAEMON="" | |
4 PYTHON="python2" | 5 PYTHON="python2" |
5 | 6 |
6 kill_process() { | 7 kill_process() { |
7 # $1 is the file containing the PID to kill, $2 is the process name | 8 # $1 is the file containing the PID to kill, $2 is the process name |
8 if [ -f $1 ]; then | 9 if [ -f $1 ]; then |
19 fi | 20 fi |
20 } | 21 } |
21 | 22 |
22 #We use python to parse config files | 23 #We use python to parse config files |
23 eval `"$PYTHON" << PYTHONEND | 24 eval `"$PYTHON" << PYTHONEND |
24 | 25 from libervia.server.constants import Const as C |
25 from sat.core.constants import Const as C | |
26 from sat.memory.memory import fixLocalDir | 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 import codecs | |
31 import locale | |
32 | |
33 sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout) | |
30 | 34 |
31 fixLocalDir() # XXX: tmp update code, will be removed in the future | 35 fixLocalDir() # XXX: tmp update code, will be removed in the future |
32 | 36 |
33 config = SafeConfigParser(defaults=C.DEFAULT_CONFIG) | 37 config = SafeConfigParser(defaults=C.DEFAULT_CONFIG) |
34 try: | 38 try: |
39 sys.exit() | 43 sys.exit() |
40 | 44 |
41 env=[] | 45 env=[] |
42 env.append("PID_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'pid_dir')),'')) | 46 env.append("PID_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'pid_dir')),'')) |
43 env.append("LOG_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'log_dir')),'')) | 47 env.append("LOG_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'log_dir')),'')) |
48 env.append("APP_NAME='%s'" % C.APP_NAME) | |
49 env.append("APP_NAME_FILE='%s'" % C.APP_NAME_FILE) | |
44 print ";".join(env) | 50 print ";".join(env) |
45 PYTHONEND | 51 PYTHONEND |
46 ` | 52 ` |
47 APP_NAME="Libervia" # FIXME: the import from Python needs libervia module to be in PYTHONPATH | |
48 APP_NAME_FILE="libervia" | |
49 PID_FILE="$PID_DIR$APP_NAME_FILE.pid" | 53 PID_FILE="$PID_DIR$APP_NAME_FILE.pid" |
50 LOG_FILE="$LOG_DIR$APP_NAME_FILE.log" | 54 LOG_FILE="$LOG_DIR$APP_NAME_FILE.log" |
51 | 55 |
52 # if there is one argument which is "stop", then we kill Libervia | 56 # if there is one argument which is "stop", then we kill Libervia |
53 if [ $# -eq 1 ];then | 57 if [ $# -eq 1 ];then |
54 if [ $1 = "stop" ];then | 58 if [ $1 = "stop" ];then |
55 kill_process $PID_FILE "$APP_NAME" | 59 kill_process $PID_FILE "$APP_NAME" |
56 exit 0 | 60 exit 0 |
57 fi | 61 elif [ $1 = "debug" ];then |
58 if [ $1 = "debug" ];then | |
59 echo "Launching $APP_NAME in debug mode" | 62 echo "Launching $APP_NAME in debug mode" |
60 DEBUG="--debug" | 63 DEBUG="--debug" |
64 elif [ $1 = "fg" ];then | |
65 echo "Launching $APP_NAME in foreground mode" | |
66 DAEMON="n" | |
61 fi | 67 fi |
62 fi | 68 fi |
63 | 69 |
64 DAEMON="n" | |
65 MAIN_OPTIONS="-${DAEMON}o" | |
66 DATA_DIR=".." | |
67 | 70 |
68 #Don't change the next line | 71 #Don't change the next lines |
72 PLUGIN_OPTIONS="-d .." | |
69 AUTO_OPTIONS="" | 73 AUTO_OPTIONS="" |
70 ADDITIONAL_OPTIONS="--pidfile $PID_FILE --logfile $LOG_FILE $AUTO_OPTIONS $DEBUG" | 74 ADDITIONAL_OPTIONS="--pidfile $PID_FILE --logfile $LOG_FILE $AUTO_OPTIONS $DEBUG" |
75 | |
76 | |
77 MAIN_OPTIONS="-${DAEMON}o" | |
71 | 78 |
72 log_dir=`dirname "$LOG_FILE"` | 79 log_dir=`dirname "$LOG_FILE"` |
73 if [ ! -d $log_dir ] ; then | 80 if [ ! -d $log_dir ] ; then |
74 mkdir $log_dir | 81 mkdir $log_dir |
75 fi | 82 fi |
76 | 83 |
77 echo "Starting $APP_NAME..." | 84 twistd $MAIN_OPTIONS $ADDITIONAL_OPTIONS $APP_NAME_FILE $PLUGIN_OPTIONS |
78 twistd $MAIN_OPTIONS $ADDITIONAL_OPTIONS $APP_NAME_FILE -d $DATA_DIR |