summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Greig <rgreig@apache.org>2007-04-19 09:33:00 +0000
committerRobert Greig <rgreig@apache.org>2007-04-19 09:33:00 +0000
commite400dd2269719b4abdf3e5321861db62375204df (patch)
tree8320a7281d4a305ab56c50658d6daa26d87e8e21
parent5d48c521f7b8410c9051e4af9e4f75ee23fcf638 (diff)
downloadqpid-python-e400dd2269719b4abdf3e5321861db62375204df.tar.gz
Merged revisions 520843 via svnmerge from
https://svn.apache.org/repos/asf/incubator/qpid/branches/M2 ........ r520843 | ritchiem | 2007-03-21 11:24:40 +0000 (Wed, 21 Mar 2007) | 1 line Added two scripts to stop the running broker without having to first record the running pid. ........ git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@530349 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/java/broker/bin/qpid.stop121
-rw-r--r--qpid/java/broker/bin/qpid.stopall57
2 files changed, 178 insertions, 0 deletions
diff --git a/qpid/java/broker/bin/qpid.stop b/qpid/java/broker/bin/qpid.stop
new file mode 100644
index 0000000000..1bffc8cdb8
--- /dev/null
+++ b/qpid/java/broker/bin/qpid.stop
@@ -0,0 +1,121 @@
+#!/bin/bash
+
+# qpid.stop Script
+#
+# Script checks for a given pid running PROGRAM and attempts to quit it
+#
+
+MAX_ATTEMPTS=5
+SLEEP_DELAY=2
+PROGRAM="org.apache.qpid.server.Main"
+
+
+#
+# Print what is going to be done
+#
+printActions()
+{
+ps=`ps o command p $1|grep $PROGRAM`
+echo "Attempting to kill: $ps"
+}
+
+#
+# Forcably Quit the specified PID($1)
+#
+forceQuit()
+{
+kill -9 $1
+}
+
+
+#
+# Gracefully ask the PID($1) to quit
+#
+quit()
+{
+kill $1
+}
+
+
+#
+# Sleep and then check then lookup the PID($1) to ensure it has quit
+#
+check()
+{
+sleep $SLEEP_DELAY
+lookup $1
+}
+
+
+#
+# Grep the ps log for the PID ($1) to ensure that it has quit
+#
+lookup()
+{
+result=`ps p $1 |grep -v grep |grep $PROGRAM |wc -l`
+}
+
+
+#
+# Verify the PID($1) is available
+#
+verifyPid()
+{
+lookup $1
+if [[ $result == 1 ]] ; then
+ brokerspid=$1
+else
+ echo "Unable to locate Qpid Process with PID $1"
+ exit -1
+fi
+}
+
+
+
+#
+# Main Run
+#
+
+# 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
+
+# Attempt to quit the process MAX_ATTEMPTS Times
+attempt=0
+while [[ $result > 0 && $attempt < $MAX_ATTEMPTS ]] ; do
+ quit $brokerspid
+ check $brokerspid
+ attempt=$[$attempt + 1]
+done
+
+
+# Check that it has quit
+if [[ $results == 0 ]] ; then
+ echo "Process quit"
+ exit 0
+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
+
+
+ # Output final status
+ if [[ $attempt == $MAX_ATTEMPTS ]] ; then
+ echo "Stopped trying to kill process: $brokerspid"
+ echo "Attempted to stop $attempt times"
+ else
+ echo "Done "
+ fi
+fi
diff --git a/qpid/java/broker/bin/qpid.stopall b/qpid/java/broker/bin/qpid.stopall
new file mode 100644
index 0000000000..f6862842c9
--- /dev/null
+++ b/qpid/java/broker/bin/qpid.stopall
@@ -0,0 +1,57 @@
+#!/bin/bash
+
+# qpid.stopall script
+#
+# Script attempts to stop all PROGRAMs running under the current user
+# Utilises qpid.stop to perform the actual stopping
+#
+
+MAX_ATTEMPTS=5
+SLEEP_DELAY=2
+PROGRAM="org.apache.qpid.server.Main"
+
+#
+# grep ps for instances of $PROGRAM and collect PIDs
+#
+lookup()
+{
+pids=`ps o pid,command |grep -v grep | grep $PROGRAM | cut -d ' ' -f 1`
+result=`echo -n $pids | wc -l`
+}
+
+
+#
+# Show the PS output for given set of pids
+#
+showPids()
+{
+ps 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