changeset 561:160b45937ed2

misc: launch script now manage "status" command, and additional arguments
author Goffi <goffi@goffi.org>
date Fri, 03 Oct 2014 18:13:48 +0200
parents 77bf2654ca0a
children 7e8356479fef
files src/libervia.sh
diffstat 1 files changed, 24 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/libervia.sh	Fri Oct 03 16:18:56 2014 +0200
+++ b/src/libervia.sh	Fri Oct 03 18:13:48 2014 +0200
@@ -50,8 +50,11 @@
 print ";".join(env)
 PYTHONEND
 `
+APP_NAME="$APP_NAME"
 PID_FILE="$PID_DIR$APP_NAME_FILE.pid"
 LOG_FILE="$LOG_DIR$APP_NAME_FILE.log"
+RUNNING_MSG="$APP_NAME is running"
+NOT_RUNNING_MSG="$APP_NAME is *NOT* running"
 
 # if there is one argument which is "stop", then we kill Libervia
 if [ $# -eq 1 ];then
@@ -64,6 +67,24 @@
     elif [ $1 = "fg" ];then
         echo "Launching $APP_NAME in foreground mode"
         DAEMON="n"
+    elif [ $1 = "status" ];then
+		if [ -f $PID_FILE ]; then
+			PID=`cat $PID_FILE`
+			ps -p$PID 2>&1 > /dev/null
+			if [ $? = 0  ];then
+				echo "$RUNNING_MSG (pid: $PID)"
+				exit 0
+			else
+				echo "$NOT_RUNNING_MSG, but a pid file is present (bad exit ?): $PID_FILE"
+				exit 2
+			fi
+		else
+			echo "$NOT_RUNNING_MSG"
+			exit 1
+		fi
+	else
+		echo "bad argument, please use one of (stop, debug, fg, status) or no argument"
+		exit 1
     fi
 fi
 
@@ -81,4 +102,6 @@
     mkdir $log_dir
 fi
 
-twistd $MAIN_OPTIONS $ADDITIONAL_OPTIONS $APP_NAME_FILE $PLUGIN_OPTIONS
+shift
+
+twistd $MAIN_OPTIONS $ADDITIONAL_OPTIONS $APP_NAME_FILE $PLUGIN_OPTIONS $@