diff 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
line wrap: on
line diff
--- a/src/libervia.sh	Thu Aug 21 16:58:10 2014 +0200
+++ b/src/libervia.sh	Sun Aug 24 18:43:45 2014 +0200
@@ -1,6 +1,7 @@
 #!/bin/sh
 
 DEBUG=""
+DAEMON=""
 PYTHON="python2"
 
 kill_process() {
@@ -21,12 +22,15 @@
 
 #We use python to parse config files
 eval `"$PYTHON" << PYTHONEND
-
-from sat.core.constants import Const as C
+from libervia.server.constants import Const as C
 from sat.memory.memory import fixLocalDir
 from ConfigParser import SafeConfigParser
 from os.path import expanduser, join
 import sys
+import codecs
+import locale
+
+sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
 
 fixLocalDir()  # XXX: tmp update code, will be removed in the future
 
@@ -41,11 +45,11 @@
 env=[]
 env.append("PID_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'pid_dir')),''))
 env.append("LOG_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'log_dir')),''))
+env.append("APP_NAME='%s'" % C.APP_NAME)
+env.append("APP_NAME_FILE='%s'" % C.APP_NAME_FILE)
 print ";".join(env)
 PYTHONEND
 `
-APP_NAME="Libervia"  # FIXME: the import from Python needs libervia module to be in PYTHONPATH
-APP_NAME_FILE="libervia"
 PID_FILE="$PID_DIR$APP_NAME_FILE.pid"
 LOG_FILE="$LOG_DIR$APP_NAME_FILE.log"
 
@@ -54,25 +58,27 @@
     if [ $1 = "stop" ];then
         kill_process $PID_FILE "$APP_NAME"
         exit 0
-    fi
-    if [ $1 = "debug" ];then
+    elif [ $1 = "debug" ];then
         echo "Launching $APP_NAME in debug mode"
         DEBUG="--debug"
+    elif [ $1 = "fg" ];then
+        echo "Launching $APP_NAME in foreground mode"
+        DAEMON="n"
     fi
 fi
 
-DAEMON="n"
-MAIN_OPTIONS="-${DAEMON}o"
-DATA_DIR=".."
 
-#Don't change the next line
+#Don't change the next lines
+PLUGIN_OPTIONS="-d .."
 AUTO_OPTIONS=""
 ADDITIONAL_OPTIONS="--pidfile $PID_FILE --logfile $LOG_FILE $AUTO_OPTIONS $DEBUG"
 
+
+MAIN_OPTIONS="-${DAEMON}o"
+
 log_dir=`dirname "$LOG_FILE"`
 if [ ! -d $log_dir ] ; then
     mkdir $log_dir
 fi
 
-echo "Starting $APP_NAME..."
-twistd $MAIN_OPTIONS $ADDITIONAL_OPTIONS $APP_NAME_FILE -d $DATA_DIR
+twistd $MAIN_OPTIONS $ADDITIONAL_OPTIONS $APP_NAME_FILE $PLUGIN_OPTIONS