You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ma...@apache.org on 2008/10/30 17:34:06 UTC

svn commit: r709199 - in /incubator/qpid/trunk/qpid/java/broker/bin: qpid.stop qpid.stopall

Author: marnie
Date: Thu Oct 30 09:34:06 2008
New Revision: 709199

URL: http://svn.apache.org/viewvc?rev=709199&view=rev
Log:
Changes to qpid stop scripts to make them work on solaris and linux and also clean up to simplify. qpid.stopall now just passes through to qpid.stop rather than go back & forth between scripts. Only retained it in case we have users currently dependent on it.

Modified:
    incubator/qpid/trunk/qpid/java/broker/bin/qpid.stop
    incubator/qpid/trunk/qpid/java/broker/bin/qpid.stopall

Modified: incubator/qpid/trunk/qpid/java/broker/bin/qpid.stop
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/broker/bin/qpid.stop?rev=709199&r1=709198&r2=709199&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/broker/bin/qpid.stop (original)
+++ incubator/qpid/trunk/qpid/java/broker/bin/qpid.stop Thu Oct 30 09:34:06 2008
@@ -20,23 +20,18 @@
 
 # qpid.stop Script
 # 
-# Script checks for a given pid running PROGRAM and attempts to quit it
+# Script checks for a given pid running DEFAULT_SEARCH and attempts to quit it
 #
 
 MAX_ATTEMPTS=1
 SLEEP_DELAY=1
-PROGRAM="DQPID"
+DEFAULT_SEARCH="PNAME=QPBRKR"
 
-
-#
-# Print what is going to be done
-#
-printActions()
-{
-#ps=`ps o command p $1|grep $PROGRAM`
-ps=`ps -o args -p $1|grep $PROGRAM`
-echo "Attempting to kill: $ps"
-}
+if [ -z "$QPID_STOP_SEARCH" ]; then
+    SEARCH=$DEFAULT_SEARCH;
+else
+    SEARCH=$QPID_STOP_SEARCH;
+fi
 
 #
 # Forcably Quit the specified PID($1)
@@ -46,7 +41,6 @@
 kill -9 $1
 }
 
-
 #
 # Gracefully ask the PID($1) to quit
 #
@@ -56,11 +50,36 @@
 }
 
 #
-# Grep the ps log for the PID ($1) to ensure that it has quit
+# grep for the session ID ($1) and return 0 for successful quit and 1 for process alive
 #
-lookup()
+lookup_pid()
 {
-result=`ps -o args -p $1 |grep -v grep |grep $PROGRAM |wc -l`
+result=`ps -e | grep $1 | wc -l`
+}
+
+#
+# grep ps for all instances of $SEARCH for the current user and collect PIDs
+#
+lookup_all_pids()
+{
+pids=`pgrep -f -U $USER $SEARCH`
+result_all=`echo -n $pids | wc -w`
+}
+
+#
+# check that the PID passed in is for a Qpid broker owned by this user and alive
+#
+validate_pid()
+{
+result=`pgrep -fl $SEARCH | grep $1 | wc -l`
+}
+
+#
+# Show the PS output for given set of pids
+#
+showPids()
+{
+ps -o user,pid,args -p $pids
 }
 
 #
@@ -70,68 +89,89 @@
 {
 echo "Waiting $SLEEP_DELAY second for $1 to exit"
 sleep $SLEEP_DELAY
-lookup $1
+lookup_pid $1
 }
 
-
-
 #
 # Verify the PID($1) is available
 #
 verifyPid()
 {
-lookup $1
+validate_pid $1
 if [[ $[$result] == 1 ]] ; then
  brokerspid=$1
 else
- echo "Unable to locate Qpid Process with PID $1"
+ echo "Unable to locate Qpid Broker Process with PID $1. Check PID and try again."
  exit -1
 fi
 }
 
 #
-# Main Run
+# Stops all Qpid brokers for current user
 #
+qpid_stopall_brokers()
+{
+for pid in $pids ; do
+    lookup_pid $pid;
+    brokerspid=$pid;
+    stop_broker $pid;
+done
+}
 
-# Check if we are killing all qpid pids or just one.
-if [[ $# == 0 ]] ; then
-	echo "Killing All Qpid Brokers for user: '$USER'"
-	qpid.stopall
-	exit $?
-else	
-	verifyPid $1
-fi
-
-printActions $brokerspid
-
+#
+# Stops Qpid broker with brokerspid id
+#
+stop_broker()
+{
 # Attempt to quit the process MAX_ATTEMPTS Times
 attempt=0
 while [[ $[$result] > 0 && $[$attempt] < $[$MAX_ATTEMPTS] ]] ; do
- quit $brokerspid
- check $brokerspid
- attempt=$[$attempt + 1]
+    quit $brokerspid
+    check $brokerspid
+    attempt=$[$attempt + 1]
 done
 
 # Check that it has quit
 if [[ $[$result] == 0 ]] ; then
- echo "Process quit"
- exit 0
+    echo "Process quit"
 else
 
  # Now attempt to force quit the process
- attempt=0
- while [[ $[$result] > 0 && $[$attempt] < $[$MAX_ATTEMPTS] ]] ; do
-  forceQuit $brokerspid
-  check $brokerspid
-  attempt=$[$attempt + 1]
- done
-
+    while [[ $[$result] > 0 && $[$attempt] < $[$MAX_ATTEMPTS] ]] ; do
+        forceQuit $brokerspid
+        check $brokerspid
+        attempt=$[$attempt + 1]
+    done
 
  # Output final status
- if [[ $[$result] > 0 && $[$attempt] == $[$MAX_ATTEMPTS] ]] ; then
-	echo "Stopped trying to kill process: $brokerspid"
-	echo "Attempted to stop $attempt times"
- else
-	echo "Done "
- fi
+    if [[ $[$result] > 0 && $[$attempt] == $[$MAX_ATTEMPTS] ]] ; then
+	    echo "Stopped trying to kill process: $brokerspid"
+	    echo "Attempted to stop $attempt times"
+    else
+	    echo "Done "
+    fi
 fi
+
+}
+
+#
+# Main Run
+#
+
+# Check if we are killing all qpid pids or just one.
+# Now uses local function qpid_stopall_brokers
+if [[ $# == 0 ]] ; then
+    lookup_all_pids
+    if [[ $[$result_all] > 0 ]] ; then
+        echo "Killing All Qpid Brokers for user: '$USER'"
+        qpid_stopall_brokers
+    else
+        echo "No Qpid Brokers found running for user: " $USER
+    fi
+	exit $result
+else	
+	verifyPid $1
+	stop_broker
+    exit $result
+fi
+

Modified: incubator/qpid/trunk/qpid/java/broker/bin/qpid.stopall
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/broker/bin/qpid.stopall?rev=709199&r1=709198&r2=709199&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/broker/bin/qpid.stopall (original)
+++ incubator/qpid/trunk/qpid/java/broker/bin/qpid.stopall Thu Oct 30 09:34:06 2008
@@ -24,51 +24,4 @@
 #  Utilises qpid.stop to perform the actual stopping
 #
 
-PROGRAM="DQPID"
-
-#
-# grep ps for instances of $PROGRAM and collect PIDs
-#
-lookup()
-{
-#pids=`ps o pid,command  | grep $PROGRAM | grep -v grep | cut -d ' ' -f 1`
-pids=`ps -ef |grep $USER | grep $PROGRAM | grep -v grep | awk '{print $2}'`
-result=`echo -n $pids | wc -w`
-}
-
-
-#
-# Show the PS output for given set of pids
-#
-showPids()
-{
-ps -o user,pid,args -p $pids
-}
-
-
-#
-# Main Run
-#
-
-lookup
-
-if [[ $[$result] == 0 ]] ; then
- echo "No Qpid Brokers found running under user '$USER'"
- exit 0
-fi
-
-for pid in $pids ; do
-
-qpid.stop $pid
-
-done
-
-# Check we have quit all
-lookup
-
-if [[ $[$result] == 0 ]] ; then
- echo "All Qpid brokers successfully quit"
-else
- echo "Some brokers were not quit"
- showPids $pids
-fi
+qpid.stop $*