comparison bin/libervia @ 1124:28e3eb3bb217

files reorganisation and installation rework: - files have been reorganised to follow other SàT projects and usual Python organisation (no more "/src" directory) - VERSION file is now used, as for other SàT projects - replace the overcomplicated setup.py be a more sane one. Pyjamas part is not compiled anymore by setup.py, it must be done separatly - removed check for data_dir if it's empty - installation tested working in virtual env - libervia launching script is now in bin/libervia
author Goffi <goffi@goffi.org>
date Sat, 25 Aug 2018 17:59:48 +0200
parents src/libervia.sh@a6bef71a7fd0
children b2d067339de3
comparison
equal deleted inserted replaced
1123:63a4b8fe9782 1124:28e3eb3bb217
1 #!/bin/sh
2
3 DEBUG=""
4 DAEMON=""
5 PYTHON="python2"
6 TWISTD="$(which twistd)"
7
8 kill_process() {
9 # $1 is the file containing the PID to kill, $2 is the process name
10 if [ -f $1 ]; then
11 PID=`cat $1`
12 if ps -p $PID > /dev/null; then
13 echo "Terminating $2... "
14 kill -INT $PID
15 else
16 echo "No running process of ID $PID... removing PID file"
17 rm -f $1
18 fi
19 else
20 echo "$2 is probably not running (PID file doesn't exist)"
21 fi
22 }
23
24 #We use python to parse config files
25 eval `"$PYTHON" << PYTHONEND
26 from libervia.server.constants import Const as C
27 from sat.memory.memory import fixLocalDir
28 from ConfigParser import SafeConfigParser
29 from os.path import expanduser, join
30 import sys
31 import codecs
32 import locale
33
34 sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
35
36 fixLocalDir() # XXX: tmp update code, will be removed in the future
37
38 config = SafeConfigParser(defaults=C.DEFAULT_CONFIG)
39 try:
40 config.read(C.CONFIG_FILES)
41 except:
42 print ("echo \"/!\\ Can't read main config ! Please check the syntax\";")
43 print ("exit 1")
44 sys.exit()
45
46 env=[]
47 env.append("PID_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'pid_dir')),''))
48 env.append("LOG_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'log_dir')),''))
49 env.append("APP_NAME='%s'" % C.APP_NAME)
50 env.append("APP_NAME_FILE='%s'" % C.APP_NAME_FILE)
51 print ";".join(env)
52 PYTHONEND
53 `
54 APP_NAME="$APP_NAME"
55 PID_FILE="$PID_DIR$APP_NAME_FILE.pid"
56 LOG_FILE="$LOG_DIR$APP_NAME_FILE.log"
57 RUNNING_MSG="$APP_NAME is running"
58 NOT_RUNNING_MSG="$APP_NAME is *NOT* running"
59
60 # if there is one argument which is "stop", then we kill Libervia
61 if [ $# -ge 1 ];then
62 if [ $1 = "stop" ];then
63 kill_process $PID_FILE "$APP_NAME"
64 exit 0
65 elif [ $1 = "debug" ];then
66 echo "Launching $APP_NAME in debug mode"
67 DEBUG="--debug"
68 elif [ $1 = "fg" ];then
69 echo "Launching $APP_NAME in foreground mode"
70 DAEMON="n"
71 elif [ $1 = "status" ];then
72 if [ -f $PID_FILE ]; then
73 PID=`cat $PID_FILE`
74 ps -p$PID 2>&1 > /dev/null
75 if [ $? = 0 ];then
76 echo "$RUNNING_MSG (pid: $PID)"
77 exit 0
78 else
79 echo "$NOT_RUNNING_MSG, but a pid file is present (bad exit ?): $PID_FILE"
80 exit 2
81 fi
82 else
83 echo "$NOT_RUNNING_MSG"
84 exit 1
85 fi
86 else
87 echo "bad argument, please use one of (stop, debug, fg, status) or no argument"
88 exit 1
89 fi
90 shift
91 fi
92
93
94 #Don't change the next lines
95 PLUGIN_OPTIONS=""
96 AUTO_OPTIONS=""
97 ADDITIONAL_OPTIONS="--pidfile $PID_FILE --logfile $LOG_FILE $AUTO_OPTIONS $DEBUG"
98
99
100 MAIN_OPTIONS="-${DAEMON}o"
101
102 log_dir=`dirname "$LOG_FILE"`
103 if [ ! -d $log_dir ] ; then
104 mkdir $log_dir
105 fi
106
107 exec $PYTHON $TWISTD $MAIN_OPTIONS $ADDITIONAL_OPTIONS $APP_NAME_FILE $PLUGIN_OPTIONS $@