Tuesday, September 13, 2011

MQM Practice

Start MQ Manager
strmqm <Queue Manger>
Stop MQ Manager
endmqm <Queue Manager>

========================= Unix Script to Start/Stop QMgrs =======================

#!/sbin/sh
#
# MQM auto startup, shutdown script
#
MQ_DIR=/var/mqm/errors
TMP_FILE=$MQ_DIR/1
MQ_SCRIPT=$MQ_DIR/2
CHLTYPE="SVRCONN|SDR|RCVR|RQSTR"
if [ -f /var/mqm/qmgrs/qm.ini ]
then
  QM=`dspmq | awk -F\( '{print $2}' | sed 's/)//g' | awk '{print $1}'`
#
# Please keep the pathern of the blanks other scrips are using these port numbers.
#
LSNR="ART.QMGR 1415:\
      BING_MGR 1425"
  case "$1" in
  start)
        for q in $QM
        do
          echo "$1ing QM: $q"
          su - mqm -c "strmqm $q"
          runmqsc $q << EOF > $TMP_FILE
            display channel(*) all
EOF
         CHL=`cat $TMP_FILE | grep CHANNEL | grep -v SYSTEM | egrep $CHLTYPE | awk '{print $1}'`
          echo "START CHANNEL('SYSTEM.ADMIN.SVRCONN')" > $MQ_SCRIPT
          for ch in $CHL
          do
            echo "START $ch" >> $MQ_SCRIPT
          done
          echo "DISPLAY CHSTATUS(*)" >> $MQ_SCRIPT
          echo "END" >> $MQ_SCRIPT
          runmqsc $q < $MQ_SCRIPT
        done

        echo $LSNR | awk -F: '{for (i=1; i<=NF; i++) print $i}; END{}' | while read QM PORT
        do
          su - mqm -c "runmqlsr -t TCP -m $QM -p $PORT &"
        done
        su - mqm -c "strmqcsv $q"
        su - mqm -c dspmq
        echo
        echo "shmem segs: `ipcs -m | grep mqm | grep -v grep | wc -l`"
        echo "listeners: `ps -ef | grep runmqlsr | wc -l`"
        echo
        ;;
  stop)
        for q in $QM
        do
          echo "$1ing $q"
          su - mqm -c "endmqm -p $q; endmqlsr -m $q"
        done
        su - mqm -c dspmq
        echo
        echo "shmem segs: `ipcs -m | grep mqm | grep -v grep | wc -l`"
        echo "listeners: `ps -ef | grep runmqlsr | wc -l`"
        echo
        sleep 2
        ID="m s"
        for id in $ID
        do
          for j in `ipcs -$id | grep mqm | awk '{print $2}' | sort | uniq`
          do
            echo "Removing semid $j"
            ipcrm -$id $j
          done
        done
        ;;
  *)
        echo "Usage: $0 { start | stop }"
        exit 1
        ;;
  esac
else
  exit 0
fi
================================Create QMGR =========================

#!/bin/sh
######################################################################
#
# Usage:
# --------
# sh wssmq.sh { -help } | {  [ -log log_path ]
#                             [ -dl ]
#                             [ -stop ]
#                             -lip local_ip
#                             -lport local_port
#                             -lqm local_q_manager }
#
# Flags:
#    -help: disply usage
#    -log: the log path (default: /tmp/mq_cmd.log)
#    -dl: delete the old MQ manager (default: false)
#    -stop: stop the running MQ manager (default: false)
#    -lip: local MQ manager IP
#    -lport: local MQ manager port
#    -lqm: local MQ manager name
#
#
#######################################################################
#
# Print Usage
#
print_usage()
{
   echo ''
   echo 'GTS MQ creation script'
   echo '------------------------------'
   echo ''
   echo 'Usage:'
   echo '   sh wssmq.sh { -help }'
   echo '        | { [ -dl ]'
   echo '            [ -stop ]'
   echo '            [ -log log_path ]'
   echo '            -lip local_IP'
   echo '            -lport local_port'
   echo '            -lqm local_q_manager }'
   echo ''
   echo 'Flags:'
   echo '   -log: the log path (default: /tmp)'
   echo '   -dl: delete the old MQ manager (default: false)'
   echo '   -stop: stop the running MQ manager (default: false)'
   echo '   -lip: local MQ manager IP'
   echo '   -lport: local MQ manager port'
   echo '   -lqm: local MQ manager name'
   echo '   -help: disply usage'
   echo ''
}
# set default values
dmqm=false
stmqm=false
logdir=/tmp
# parse flags
while [ "${1}" ]
do
   case ${1} in
      "-help")
         print_usage;
         exit 1
         ;;
      "-dl")
         dmqm=true
         shift 1
         ;;
     "-stop")
         stmqm=true
         shift 1
         ;;
      "-log")
         logdir=${2}
         shift 2
         ;;
      "-lip")
         lip=${2}
         shift 2
         ;;
      "-lport")
         lport=${2}
         shift 2
         ;;
      "-lqm")
         lqm=${2}
         shift 2
         ;;
      *)
         echo "Program $0 does not recognize option $1"
         exit 1
         ;;
   esac
done
# check required variables
if [ -z "${lip}" -o -z "${lport}" -o -z "${lqm}" ]; then
   echo "Missing arguments"
   exit 1
fi
echo '********************************************************'
echo "Start MQ creation script: `/usr/ucb/whoami` in host `uname -n`"
echo '********************************************************'
# define script path
script=${logdir}/mqm_cfg_cmd.sh
# define log file
log=${logdir}/mqm_cfg_cmd.log
if [ ${stmqm} = 'true' ]; then
   echo 'Stop GTS MQ manager ...'
   endmqm -p ${lqm}
   endmqlsr -m ${lqm}
   echo 'Done'
fi
if [ ${dmqm} = 'true' ]; then
   echo 'Delete GTS MQ manager ...'
   dltmqm ${lqm}
   echo 'Done'
fi
echo 'Creating GTS MQ manager ...'
crtmqm -ll -lf 32000 -lp 10 -ls 3 -u DEAD.LETTER.QUEUE -ld /var/mqm/share/log -md /var/mqm/share/qmgrs ${lqm}
strmqm -x ${lqm}
nohup runmqlsr -t tcp -p ${lport} -m ${lqm} >/dev/null 2>&1 &
sleep 5
echo 'Done'
echo 'Creating queues and channels ...'
echo > ${script}
# define dead letter queue
 echo "DEFINE QLOCAL('DEAD.LETTER.QUEUE')" >> ${script}
echo "ALTER QMGR DEADQ('DEAD.LETTER.QUEUE')" >> ${script}
# define local queues
echo "DEFINE QLOCAL('GOWEEKEND_DEAL_QUEUE') DESCR ('GTS50UAT')" >> ${script}

echo "DEFINE QLOCAL('EFX_DEAL_QUEUE') DESCR ('EFX Deal Request')" >> ${script}
echo "DEFINE QLOCAL('EFX_DEAL_ACK_QUEUE') DESCR ('EFX Deal Acknowledge')" >> ${script}
echo "DEFINE QLOCAL('EFXGTS_DEAL_ACK_QUEUE') DESCR ('EFX GTS Deal ACK')" >> ${script}

echo "DEFINE QLOCAL('OW_DEAL_QUEUE') DESCR ('OW Deal Request')" >> ${script}
echo "DEFINE QLOCAL('OW_DEAL_ACK_QUEUE') DESCR ('OW Deal Acknowledge')" >> ${script}
echo "DEFINE QLOCAL('DLB_DEAL_QUEUE') DESCR ('DLB Deal Request')" >> ${script}
echo "DEFINE QLOCAL('DLB_DEAL_ACK_QUEUE') DESCR ('DLB Deal Acknowledge')" >> ${script}
echo "DEFINE QLOCAL('DLBGTS_DEAL_ACK_QUEUE') DESCR ('DLB GTS Deal Ack')" >> ${script}
echo "DEFINE QLOCAL('ETM_DEAL_QUEUE') DESCR ('ETM Deal Request')" >> ${script}
echo "DEFINE QLOCAL('ETM_DEAL_ACK_QUEUE') DESCR ('ETM Deal Acknowledge')" >> ${script}
echo "DEFINE QLOCAL('ETMGTS_DEAL_ACK_QUEUE') DESCR ('ETM GTS Deal Ack')" >> ${script}

echo "DEFINE QLOCAL('MXG_DEAL_QUEUE')DESCR ('Outbound MXG deal Queue')" >> ${script}

echo "DEFINE QLOCAL('EFX_ADMIN_QUEUE')" >> ${script}
echo "DEFINE QLOCAL('EFX_ADMIN_ACK_QUEUE')" >> ${script}

# define server connection channel
echo "DEFINE CHANNEL('GTS50UAT_4X_MGR.CHL') CHLTYPE(SVRCONN) " >> ${script}
# define server admin channel
echo "DEFINE CHANNEL('MQEXPLORER') CHLTYPE(SVRCONN) " >> ${script}
# start channels
echo  >> ${script}
echo "START CHANNEL('GTSUAT.SVRCONN')" >> ${script}
echo "START CHANNEL('MQEXPLORER')" >> ${script}
echo  "END" >> ${script}
# run script
runmqsc ${lqm} < ${script} > ${log}
rm -f ${script}
echo "! ! ! ALL DONE ! ! !"

===================== mqmAuth.sh ==================================
#!/bin/ksh
qmgrName=$1
userName=$2
if [ -z "${userName}" ] || [ -z "${qmgrName}" ]; then
  echo "%%MQM-E-SYNTAX, wrong syntax."
  echo "%%MQM-I-USAGE, usage:"
  echo "                     $0 <QManager Name> <user name>"
  exit ${LINENO}
fi
id $userName
if [ $? -ne 0 ]; then
  echo "%%MQM-E-USER, user ${userName} is not found. Please contact `hostname` adminstrator."
  exit ${LINENO}
fi
setmqaut -m ${qmgrName} -t qmgr -g ${userName} +inq +connect +dsp
setmqaut -m ${qmgrName} -n '**' -t queue -g ${userName} +browse +dsp
setmqaut -m ${qmgrName} -n SYSTEM.ADMIN.COMMAND.QUEUE -t  queue -g ${userName} +inq +put +dsp
setmqaut -m ${qmgrName} -n SYSTEM.MQEXPLORER.REPLY.MODEL -t queue  -g ${userName} +inq +browse +get +dsp
setmqaut -m ${qmgrName}  -n SYSTEM.DEFAULT.MODEL.QUEUE -t queue -g ${userName} +inq +browse +get
setmqaut -m ${qmgrName}  -n '**' -t topic -g ${userName} +dsp
setmqaut -m ${qmgrName} -n '**' -t channel -g ${userName} +dsp
setmqaut -m ${qmgrName} -n '**' -t clntconn -g ${userName} +dsp
setmqaut -m ${qmgrName} -n '**' -t authinfo -g ${userName} +dsp
setmqaut -m ${qmgrName} -n '**' -t listener -g ${userName} +dsp
setmqaut -m ${qmgrName} -n '**' -t namelist -g ${userName} +dsp
setmqaut -m ${qmgrName} -n '**' -t process -g ${userName} +dsp
setmqaut -m ${qmgrName} -n '**' -t service -g ${userName} +dsp

No comments:

Post a Comment