#!/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                                                      
#                                                                              
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r720 src/43haes/usr/sbin/cluster/sa/wmq/sbin/cl_wmq_start.sh 1.3 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2011 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)  7d4c34b 43haes/usr/sbin/cluster/sa/wmq/sbin/cl_wmq_start.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM
#########################################################################################
# 
# NAME: 
#       cl_wmq_start
#
# PURPOSE:
#       This script is intended to use by PowerHA,
#            to start the specified Queue manager and its associated listeners.
#
# Flags:
#	u : MQM user name.
#	m : MQ instance name.
# 
# ARGUMENTS: 
#	mqm user name.
#	Queue manager instance name.
#
# RETURNS:  0 on success
#           1 on failure
############################################################################### 

function start_mqm {
	[[ "$VERBOSE_LOGGING" == "high" ]] && set -x
	KLIB_SA_logmsg INFO 2 1 wmq_sa.cat "Starting the WebSphere MQ \
server with Queue Manager %1\$s and user as %2\$s" $QM $MQU

	# The strmqm command does not use the -x flag.
	/usr/bin/su $MQU -c "/usr/mqm/bin/strmqm $QM"
	RC=$?

	# Success while starting
	(( $RC == 0 )) && {
		KLIB_SA_logmsg INFO 2 2 wmq_sa.cat "Successfully started the \
WebSphere MQ server with Queue Manager %1\$s and user as %2\$s" $QM $MQU

                # Start all the associated MQ listeners
                typeset LSNRS=$(clodmget -n -q "name = "RESTART_METHOD"" -f value HACMPmonitor | grep -w "$QM -l" | awk '{print $NF}')
                for LSNR in $LSNRS; do
                     $WMQ_HA_SBIN/cl_wmq_startlsnr -u $MQU -m $QM -l $LSNR
                     RC=$?
                     (( RC != 0 )) && break
                done

		return $RC
	}

	# Failure while starting
	KLIB_SA_logmsg ERROR 2 3 wmq_sa.cat "Failed starting the WebSphere MQ server \
with Queue Manager %1\$s and user as %2\$s" $QM $MQU
	return $RC
}

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

typeset MQU
typeset QM

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

[[ -z $MQU || -z $QM ]] && exit 1
start_mqm
