comparison bin/sat @ 2562:26edcf3a30eb

core, setup: huge cleaning: - moved directories from src and frontends/src to sat and sat_frontends, which is the recommanded naming convention - move twisted directory to root - removed all hacks from setup.py, and added missing dependencies, it is now clean - use https URL for website in setup.py - removed "Environment :: X11 Applications :: GTK", as wix is deprecated and removed - renamed sat.sh to sat and fixed its installation - added python_requires to specify Python version needed - replaced glib2reactor which use deprecated code by gtk3reactor sat can now be installed directly from virtualenv without using --system-site-packages anymore \o/
author Goffi <goffi@goffi.org>
date Mon, 02 Apr 2018 19:44:50 +0200
parents src/sat.sh@a34b4fca16e2
children ab2696e34d29
comparison
equal deleted inserted replaced
2561:bd30dc3ffe5a 2562:26edcf3a30eb
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 printf "Terminating $2... "
14 kill $PID
15 while ps -p $PID > /dev/null; do
16 sleep 0.2
17 done
18 printf "OK\n"
19 else
20 echo "No running process of ID $PID... removing PID file"
21 rm -f $1
22 fi
23 else
24 echo "$2 is probably not running (PID file doesn't exist)"
25 fi
26 }
27
28 #We use python to parse config files
29 eval `"$PYTHON" << PYTHONEND
30 from sat.core.constants import Const as C
31 from sat.memory.memory import fixLocalDir
32 from ConfigParser import SafeConfigParser
33 from os.path import expanduser, join
34 import sys
35 import codecs
36 import locale
37
38 sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
39
40 fixLocalDir() # XXX: tmp update code, will be removed in the future
41
42 config = SafeConfigParser(defaults=C.DEFAULT_CONFIG)
43 try:
44 config.read(C.CONFIG_FILES)
45 except:
46 print ("echo \"/!\\ Can't read main config ! Please check the syntax\";")
47 print ("exit 1")
48 sys.exit()
49
50 env=[]
51 env.append("PID_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'pid_dir')),''))
52 env.append("LOG_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'log_dir')),''))
53 env.append("APP_NAME='%s'" % C.APP_NAME)
54 env.append("APP_NAME_FILE='%s'" % C.APP_NAME_FILE)
55 print ";".join(env)
56 PYTHONEND
57 `
58 APP_NAME="$APP_NAME"
59 PID_FILE="$PID_DIR$APP_NAME_FILE.pid"
60 LOG_FILE="$LOG_DIR$APP_NAME_FILE.log"
61 RUNNING_MSG="$APP_NAME is running"
62 NOT_RUNNING_MSG="$APP_NAME is *NOT* running"
63
64 # if there is one argument which is "stop", then we kill SaT
65 if [ $# -eq 1 ];then
66 if [ $1 = "stop" ];then
67 kill_process $PID_FILE "$APP_NAME"
68 exit 0
69 elif [ $1 = "debug" ];then
70 echo "Launching $APP_NAME in debug mode"
71 DEBUG="--debug"
72 elif [ $1 = "fg" ];then
73 echo "Launching $APP_NAME in foreground mode"
74 DAEMON="n"
75 elif [ $1 = "status" ];then
76 if [ -f $PID_FILE ]; then
77 PID=`cat $PID_FILE`
78 ps -p$PID 2>&1 > /dev/null
79 if [ $? = 0 ];then
80 echo "$RUNNING_MSG (pid: $PID)"
81 exit 0
82 else
83 echo "$NOT_RUNNING_MSG, but a pid file is present (bad exit ?): $PID_FILE"
84 exit 2
85 fi
86 else
87 echo "$NOT_RUNNING_MSG"
88 exit 1
89 fi
90 else
91 echo "bad argument, please use one of (stop, debug, fg, status) or no argument"
92 exit 1
93 fi
94 fi
95
96 MAIN_OPTIONS="-${DAEMON}o"
97
98 #Don't change the next lines
99 AUTO_OPTIONS=""
100 ADDITIONAL_OPTIONS="--pidfile $PID_FILE --logfile $LOG_FILE $AUTO_OPTIONS $DEBUG"
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