diff options
| author | Robert Greig <rgreig@apache.org> | 2007-04-19 09:33:00 +0000 |
|---|---|---|
| committer | Robert Greig <rgreig@apache.org> | 2007-04-19 09:33:00 +0000 |
| commit | f451f89b8793735b2d1dc43db596c33178061849 (patch) | |
| tree | e76cdaae26c88f103d1e3bce311fdc9aa4c43a4f /java/broker | |
| parent | b8a0aaa205cc7aeb28705c9c18e5ed46a2089398 (diff) | |
| download | qpid-python-f451f89b8793735b2d1dc43db596c33178061849.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/qpid@530349 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/broker')
| -rw-r--r-- | java/broker/bin/qpid.stop | 121 | ||||
| -rw-r--r-- | java/broker/bin/qpid.stopall | 57 |
2 files changed, 178 insertions, 0 deletions
diff --git a/java/broker/bin/qpid.stop b/java/broker/bin/qpid.stop new file mode 100644 index 0000000000..1bffc8cdb8 --- /dev/null +++ b/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/java/broker/bin/qpid.stopall b/java/broker/bin/qpid.stopall new file mode 100644 index 0000000000..f6862842c9 --- /dev/null +++ b/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 |
