changeset 418:ec8775575886

misc: libervia stop would not kill all libervia instances anymore
author souliane <souliane@mailoo.org>
date Sun, 23 Mar 2014 23:06:12 +0100
parents 2bd609d7dd65
children 454c7685471d
files libervia_server/libervia.sh
diffstat 1 files changed, 32 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/libervia_server/libervia.sh	Sun Mar 23 23:05:23 2014 +0100
+++ b/libervia_server/libervia.sh	Sun Mar 23 23:06:12 2014 +0100
@@ -1,21 +1,25 @@
 #!/bin/sh
 
-#if there is one argument which is "stop", then we kill libervia
 DEBUG=""
-if [ $# -eq 1 ];then
-    if [ $1 = "stop" ];then
-        echo "Terminating Libervia"
-        pkill -f "twistd.*libervia"
-        exit 0
+NAME="libervia"
+FULL_NAME="Libervia"
+PYTHON="python2"
+
+kill_process() {
+    # $1 is the file containing the PID to kill, $2 is the process name
+    if [ -f $1 ]; then
+        PID=`cat $1`
+        if ps -p $PID > /dev/null; then
+            echo "Terminating $2"
+            kill -INT $PID
+        else
+            echo "No running process of ID $PID... removing PID file"
+            rm -f $1
+        fi
+    else
+        echo "$2 is probably not running (PID file doesn't exist)"
     fi
-    if [ $1 = "debug" ];then
-        echo "Launching Libervia in debug mode"
-        DEBUG="--debug"
-    fi
-fi
-
-NAME='libervia'
-PYTHON='python'
+}
 
 #We use python to parse config files
 eval `"$PYTHON" << PYTHONEND
@@ -42,6 +46,19 @@
 
 PID_FILE="$PID_DIR$NAME.pid"
 LOG_FILE="$LOG_DIR$NAME.log"
+
+# if there is one argument which is "stop", then we kill Libervia
+if [ $# -eq 1 ];then
+    if [ $1 = "stop" ];then
+        kill_process $PID_FILE "$FULL_NAME"
+        exit 0
+    fi
+    if [ $1 = "debug" ];then
+        echo "Launching $FULL_NAME in debug mode"
+        DEBUG="--debug"
+    fi
+fi
+
 DAEMON="n"
 MAIN_OPTIONS="-${DAEMON}o"
 
@@ -54,5 +71,5 @@
     mkdir $log_dir
 fi
 
-echo "Starting Libervia..."
+echo "Starting $FULL_NAME..."
 twistd $MAIN_OPTIONS $ADDITIONAL_OPTIONS $NAME