#!/usr/bin/ksh93
#  ALTRAN_PROLOG_BEGIN_TAG                                                    
#  This is an automatically generated prolog.                                  
#                                                                              
#  Copyright (C) Altran ACT S.A.S. 2019,2021.  All rights reserved.  
#                                                                              
#  ALTRAN_PROLOG_END_TAG                                                      
#                                                                              
# @(#)  7d4c34b 43haes/usr/sbin/cluster/sa/wmq/sbin/cl_wmq_stoplsnr.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM
#########################################################################################
#
# NAME:
#       cl_wmq_stoplsnr
#
# PURPOSE:
#       This script is intended to use by PowerHA to stop the specified mq listener.
#
# Flags/Arguments:
#               u : MQM user name.
#               m : MQ instance name.
#               l : MQ listener name.
#
# RETURNS:  0 on success
#           1 on failure
###############################################################################

function stop_mqlsnr {
        [[ "$VERBOSE_LOGGING" == "high" ]] && set -x
        KLIB_SA_logmsg INFO 2 16 wmq_sa.cat "Stopping the WebSphere MQ listener %1\$s \
associated with Queue Manager %2\$s" $LSNR $QM

        echo "STOP LISTENER($LSNR)" | /usr/bin/su $MQU -c "/usr/mqm/bin/runmqsc $QM"
        RC=$?

        # Successfully stopped listener
        (( $RC == 0 )) && {
                KLIB_SA_logmsg INFO 2 17 wmq_sa.cat "Successfully stopped the WebSphere \
MQ listener %1\$s associated with Queue Manager %2\$s" $LSNR $QM
                return 0
        }

        # listener already stopped
        (( $RC == 10 )) && {
                KLIB_SA_logmsg INFO 2 18 wmq_sa.cat "WebSphere MQ listener %1\$s \
associated with Queue Manager %2\$s is already stopped" $LSNR $QM
                return 0
        }

        # Failed while stopping the listener
        KLIB_SA_logmsg ERROR 2 19 wmq_sa.cat "Failed while stopping the WebSphere \
MQ listener %1\$s associated with Queue Manager %2\$s.\n\
The Queue Manager might be down or stopped." $LSNR $QM
        return $RC
}

############
#MAIN
############
[[ "$VERBOSE_LOGGING" == "high" ]] && set -x
. /usr/es/sbin/cluster/sa/wmq/sbin/cl_wmq_Globals

typeset MQU
typeset QM
typeset LSNR

while getopts u:m:l: opt
do
        case $opt in
                u)# MQ User name.
                        MQU=$OPTARG
                        ;;

                m)# QM instance name.
                        QM=$OPTARG
                        ;;

                l)# MQ Listener name.
                        LSNR=$OPTARG
                        ;;
        esac
done

[[ -z $MQU || -z $QM || -z $LSNR ]] && exit 1
stop_mqlsnr
