Example shell script for stopping an HA cluster queue manager on UNIX and Linux
In most cases, we can use a shell script to stop a queue manager. Examples of suitable shell scripts are given here. We can tailor these to your needs and use them to stop the queue manager under control of our HA cluster.
The following script is an example of how to immediately stop a queue manager without making assumptions about the current state of the queue manager. The script must be run by the mqm user. It might therefore be necessary to wrap this script in a shell script to switch the user from the HA cluster user to mqm. (An example shell script is provided in Example shell scripts for starting an HA cluster queue manager on UNIX and Linux.)#!/bin/ksh # # The script ends the QM by using two phases, initially trying an immediate # end with a time-out and escalating to a forced stop of remaining # processes. # # The script must be run by the mqm user. # # There are two arguments: the queue manager name and a timeout value. QM=$1 TIMEOUT=$2 if [ -z "$QM" ] then echo "ERROR! No queue manager name supplied" exit 1 fi if [ -z "$TIMEOUT" ] then echo "ERROR! No timeout specified" exit 1 fi for severity in immediate brutal do # End the queue manager in the background to avoid # it blocking indefinitely. Run the TIMEOUT timer # at the same time to interrupt the attempt, and try a # more forceful version. If the brutal version fails, # nothing more can be done here. echo "Attempting ${severity} end of queue manager '${QM}'" case $severity in immediate) # Minimum severity of endmqm is immediate which severs connections. # HA cluster should not be delayed by clients endmqm -i ${QM} & ;; brutal) # This is a forced means of stopping queue manager processes. srchstr="( |-m)$QM *.*$" for process in amqzmuc0 amqzxma0 amqfcxba amqfqpub amqpcsea amqzlaa0 \ amqzlsa0 runmqchi runmqlsr amqcrsta amqrrmfa amqrmppa \ amqzfuma amqzmuf0 amqzmur0 amqzmgr0 do ps -ef | tr "\t" " " | grep $process | grep -v grep | \ egrep "$srchstr" | awk '{print $2}'| \ xargs kill -9 > /dev/null 2>&1 done esac TIMED_OUT=yes SECONDS=0 while (( $SECONDS < ${TIMEOUT} )) do TIMED_OUT=yes i=0 while [ $i -lt 5 ] do # Check for execution controller termination srchstr="( |-m)$QM *.*$" cnt=`ps -ef | tr "\t" " " | grep amqzxma0 | grep -v grep | \ egrep "$srchstr" | awk '{print $2}' | wc -l ` i=`expr $i + 1` sleep 1 if [ $cnt -eq 0 ] then TIMED_OUT=no break fi done if [ ${TIMED_OUT} = "no" ] then break fi echo "Waiting for ${severity} end of queue manager '${QM}'" sleep 1 done # timeout loop if [ ${TIMED_OUT} = "yes" ] then continue # to next level of urgency else break # queue manager is ended, job is done fi done # next phaseNote: Depending on what processes are running for a specific queue manager, the list of queue manager processes included in this script might either not be a complete list or might include more processes than the processes that are running for that queue manager:
for process in amqzmuc0 amqzxma0 amqfcxba amqfqpub amqpcsea amqzlaa0 \ amqzlsa0 runmqchi runmqlsr amqcrsta amqrrmfa amqrmppa \ amqzfuma amqzmuf0 amqzmur0 amqzmgr0
A process can be included in or excluded from this list based on what feature is configured and what processes are running for a specific queue manager. For a complete list of processes and information about stopping the processes in a specific order, see Stopping a queue manager manually on UNIX and Linux .
Parent topic: HA clusters on UNIX and Linux