activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r1096629 - /activemq/activemq-apollo/trunk/apollo-cli/src/main/resources/org/apache/activemq/apollo/cli/commands/bin/apollo-broker-service
Date Mon, 25 Apr 2011 23:08:37 GMT
Author: chirino
Date: Mon Apr 25 23:08:37 2011
New Revision: 1096629

URL: http://svn.apache.org/viewvc?rev=1096629&view=rev
Log:
Check to see if the service is running before starting a new instance.

Modified:
    activemq/activemq-apollo/trunk/apollo-cli/src/main/resources/org/apache/activemq/apollo/cli/commands/bin/apollo-broker-service

Modified: activemq/activemq-apollo/trunk/apollo-cli/src/main/resources/org/apache/activemq/apollo/cli/commands/bin/apollo-broker-service
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-cli/src/main/resources/org/apache/activemq/apollo/cli/commands/bin/apollo-broker-service?rev=1096629&r1=1096628&r2=1096629&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-cli/src/main/resources/org/apache/activemq/apollo/cli/commands/bin/apollo-broker-service
(original)
+++ activemq/activemq-apollo/trunk/apollo-cli/src/main/resources/org/apache/activemq/apollo/cli/commands/bin/apollo-broker-service
Mon Apr 25 23:08:37 2011
@@ -53,77 +53,94 @@ fi
 
 PID_FILE="${APOLLO_BASE}/data/apollo.pid"
 
-stop() {
-    if [ -f ${PID_FILE} ] ; then
+status() {
+  if [ -f "${PID_FILE}" ] ; then
     pid=`cat "${PID_FILE}"`
-    kill $@ ${pid}
-
     # check to see if it's gone...
-    for i in 1 2 3 4 5 ; do
-      ps -p ${pid} > /dev/null
-      if [ $? -ne 0 ] ; then
-        rm "${PID_FILE}"
-        exit 0
-      fi
-      sleep 1
-    done
+    ps -p ${pid} > /dev/null
+    if [ $? -eq 0 ] ; then
+      return 1
+    else
+      rm ${PID_FILE}
+    fi
+  fi
+  return 0
+}
 
-    echo Could not stop process ${pid}
-    exit 1
+stop() {
+  if [ -f "${PID_FILE}" ] ; then
+    pid=`cat "${PID_FILE}"`
+    kill $@ ${pid} > /dev/null
   fi
+  for i in 1 2 3 4 5 ; do
+    status
+    if [ $? -eq 0 ] ; then
+      return 0
+    fi
+    sleep 1
+  done
+  echo Could not stop process ${pid}
+  return 1
 }
 
 start() {
+
+  status
+  if [ $? -eq 1 ] ; then
+    echo "Allready running."
+    return 1
+  fi
+
   if [ -z "$APOLLO_USER" ] ; then
     nohup ${APOLLO_BASE}/bin/apollo-broker run > /dev/null 2> /dev/null &
   else
-    sudo -u ${APOLLO_USER} nohup ${APOLLO_BASE}/bin/apollo-broker run > /dev/null 2>
/dev/null &
+    sudo -n -u ${APOLLO_USER} nohup ${APOLLO_BASE}/bin/apollo-broker run > /dev/null 2>
/dev/null &
   fi
-  rc=$?
-  if [ $rc -eq 0 ] ; then
-    echo $! > "${PID_FILE}"
-  else
-    exit $rc
+
+  echo $! > "${PID_FILE}"
+
+  # check to see if stays up...
+  sleep 1
+  status
+  if [ $? -eq 0 ] ; then
+    echo "Could not start ${service}"
+    return 1
   fi
+  return 0
 }
 
 case $1 in
   start)
     echo "Starting ${service}"
     start
+    exit $?
   ;;
 
   force-stop)
     echo "Forcibly Stopping ${service}"
     stop -9
-    exit 0
+    exit $?
   ;;
 
   stop)
     echo "Gracefully Stopping ${service}"
     stop
-    exit 0
+    exit $?
   ;;
 
   restart)
     echo "Restarting ${service}"
     stop
     start
-    exit 0
+    exit $?
   ;;
 
   status)
-    if [ -f ${PID_FILE} ] ; then
-      pid=`cat "${PID_FILE}"`
-      # check to see if it's gone...
-      ps -p ${pid} > /dev/null
-      if [[ $? -ne 0 ]] ; then
-        echo "${service} is stopped"
-      else
-        echo  "${service} is running"
-      fi
-    else
+    status
+    if [ $? -eq 0 ] ; then
       echo "${service} is stopped"
+    else
+      echo  "${service} is running"
     fi
     exit 0
   ;;
@@ -131,4 +148,4 @@ case $1 in
   *)
     echo "Usage: $0 {start|stop|restart|force-stop|status}" >&2
     exit 2
-esac
+esac
\ No newline at end of file



Mime
View raw message