1 # 2 # CDDL HEADER START 3 # 4 # The contents of this file are subject to the terms of the 5 # Common Development and Distribution License (the License). 6 # You may not use this file except in compliance with the License. 7 # 8 # You can obtain a copy of the license at usr/src/CDDL.txt 9 # or http://www.opensolaris.org/os/licensing. 10 # See the License for the specific language governing permissions 11 # and limitations under the License. 12 # 13 # When distributing Covered Code, include this CDDL HEADER in each 14 # file and include the License file at usr/src/CDDL.txt. 15 # If applicable, add the following below this CDDL HEADER, with the 16 # fields enclosed by brackets [] replaced with your own identifying 17 # information: Portions Copyright [yyyy] [name of copyright owner] 18 # 19 # CDDL HEADER END 20 # 21 22 # 23 # Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24 # Use is subject to license terms. 25 # 26 #ident "@(#)functions.ksh 1.10 07/08/07 SMI" 27 # 28 29 PKG=SUNWscmqs 30 MYNAME=`basename $0` 31 MYDIR=`dirname $0` 32 MYTMPDIR=/var/tmp 33 LOGFILE=${MYTMPDIR}/${RESOURCE}_logfile 34 TASK_COMMAND="" 35 PATTERN="\<${QMGR}\>|\<m${QMGR}\>" 36 RESOURCE_PROJECT_NAME="" 37 SCLOGGER=/usr/cluster/lib/sc/scds_syslog 38 LOGGER=/usr/bin/logger 39 40 syslog_tag() 41 { 42 ${SET_DEBUG} 43 print "SC[${PKG:-??}.${COMPONENT:-??}.${METHOD:-??}]:${RESOURCEGROUP:-??}:${RESOURCE:-??}" 44 } 45 46 scds_syslog() 47 { 48 if [ -f ${SCLOGGER} ] 49 then 50 ${SCLOGGER} "$@" & 51 else 52 while getopts 'p:t:m' opt 53 do 54 case "${opt}" in 55 t) TAG=${OPTARG};; 56 p) PRI=${OPTARG};; 57 esac 58 done 59 60 shift $((${OPTIND} - 1)) 61 LOG_STRING=`/usr/bin/printf "$@"` 62 ${LOGGER} -p ${PRI} -t ${TAG} ${LOG_STRING} 63 fi 64 } 65 66 debug_message() 67 { 68 if [ "${DEBUG}" = "${RESOURCE}" -o "${DEBUG}" = "ALL" ] 69 then 70 SET_DEBUG="set -x" 71 DEBUG_TEXT=${1} 72 73 scds_syslog -p daemon.debug -t $(syslog_tag) -m \ 74 "%s" "${DEBUG_TEXT}" 75 else 76 SET_DEBUG= 77 fi 78 } 79 80 log_message() 81 { 82 debug_message "Function: log_message - Begin" 83 ${SET_DEBUG} 84 85 if [ -s "${LOGFILE}" ] 86 then 87 PRIORITY=$1 88 HEADER=$2 89 90 strings ${LOGFILE} > ${LOGFILE}.copy 91 92 while read MSG_TXT 93 do 94 scds_syslog -p daemon.${PRIORITY} -t $(syslog_tag) -m \ 95 "%s - %s" \ 96 "${HEADER}" "${MSG_TXT}" 97 done < ${LOGFILE}.copy 98 99 cat /dev/null > ${LOGFILE} 100 fi 101 102 debug_message "Function: log_message - End" 103 } 104 105 set_redirection() 106 { 107 debug_message "Function: set_redirection - Begin" 108 ${SET_DEBUG} 109 110 if /usr/bin/getent passwd ${USERID} | /usr/bin/awk -F: '{print $7}' | /usr/bin/grep csh > /dev/null 111 then 112 OUTPUT=">& ${LOGFILE}" 113 else 114 OUTPUT="> ${LOGFILE} 2>&1" 115 fi 116 117 debug_message "Function: set_redirection - End" 118 } 119 120 query_pids() 121 { 122 debug_message "Function: query_pids - Begin" 123 ${SET_DEBUG} 124 125 # Usage: query_pids "parameter" 126 # 127 # "parameter" is passed to /usr/xpg4/bin/grep 128 # 129 # Currently, query_pids() is used as follows, 130 # 131 # query_pids "-w amqzxma0" 132 # query_pids "-v runmqlsr" 133 # query_pids "-c -E 'amqzmuc0|amqzxma0'" 134 # query_pids "-c -E 'amqzxma0|amqhasmx'" 135 # query_pids "-w runmqsc" 136 # query_pids "-w amqpcsea" 137 # query_pids "-w runmqlsr | /usr/bin/grep '\\-p ${port}' " 138 # query_pids "-w 'runmqchi -m ${QMGR} -q ${INITQNAME}' " 139 # query_pids "-w 'runmqtrm -m ${QMGR} -q ${TRMQ}' " 140 # 141 # Output: rc=0 if the query is TRUE, else rc=1 142 # ${pids} contains the queried process ids 143 # 144 # If being run on Solaris 10, query_pids() matches the 145 # correct zonename, otherwise zones are ignored for 146 # pre-Solaris 10 systems. 147 # 148 # query_pids() matches against the correct queue manager 149 # name and will exclude "queue.manager" names, i.e. exclude 150 # a similar queue manager name that uses the "." notation. 151 # 152 # To avoid excluding Channel Initiator or Trigger Monitor 153 # queues that use the "." notation, "excluding" is turned 154 # off when running the "test" and "stop" methods for the 155 # Channel Initiator or Trigger Monitor queries. 156 # 157 # Queries for Channel Initiator or Trigger Monitor supply 158 # distinct pattern matches that include the queue manager 159 # name, which means we do not need to exclude "." entries. 160 161 rc=1 162 163 EXCLUDE= 164 PROCESS= 165 [ "${1}" ] && PROCESS="| /usr/xpg4/bin/grep ${1}" 166 167 # If ${QMGR} is not a "queue.manager" notation then 168 # exclude any ${QMGR}"." and ${QMGR}"!" entries 169 170 if ! /usr/bin/echo ${QMGR} | /usr/bin/grep '\.' > /dev/null 171 then 172 EXCLUDE="| /usr/xpg4/bin/grep -v -E '${QMGR}\.|${QMGR}\!'" 173 fi 174 175 if [ "${METHOD}" != "start" ] 176 then 177 if [ "${COMPONENT}" = "chi" -o "${COMPONENT}" = "trm" ] 178 then 179 EXCLUDE= 180 fi 181 fi 182 183 if [ -x /sbin/zonename ] 184 then 185 pids=`/usr/bin/ps -u mqm -o pid,args,zone | /usr/bin/grep " ${ZONENAME}$" | \ 186 eval /usr/xpg4/bin/grep -E '${PATTERN}' ${EXCLUDE} ${PROCESS} | /usr/bin/awk '{print $1}'` 187 else 188 pids=`/usr/bin/ps -u mqm -o pid,args | \ 189 eval /usr/xpg4/bin/grep -E '${PATTERN}' ${EXCLUDE} ${PROCESS} | /usr/bin/awk '{print $1}'` 190 fi 191 192 [ "${pids}" ] && rc=0 193 194 debug_message "Function: query_pids - End" 195 return ${rc} 196 } 197 198 validate() 199 { 200 debug_message "Function: validate - Begin" 201 ${SET_DEBUG} 202 203 rc=0 204 205 if /usr/bin/getent passwd mqm > /dev/null 206 then 207 debug_message "Validate - User mqm exists" 208 else 209 # SCMSGS 210 # @explanation 211 # The userid mqm does not exist. 212 # @user_action 213 # The userid mqm must exist within /etc/passwd. 214 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 215 "Validate - User mqm does not exist" 216 rc=1 217 fi 218 219 if /usr/bin/getent group mqm > /dev/null 220 then 221 debug_message "Validate - Group mqm exists" 222 else 223 # SCMSGS 224 # @explanation 225 # The group mqm does not exist. 226 # @user_action 227 # The group mqm must exist within /etc/group. 228 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 229 "Validate - Group mqm does not exist" 230 rc=1 231 fi 232 233 if [ "${USERID}" = "mqm" ] 234 then 235 debug_message "Validate - Userid is mqm" 236 else 237 pgroup=`/usr/bin/getent passwd ${USERID} | /usr/bin/awk -F: '{print $4}'` 238 239 if [ "${pgroup}" ] 240 then 241 if /usr/bin/getent group ${pgroup} | /usr/bin/awk -F: '{ if ($1 == "mqm") print $3}' | \ 242 /usr/bin/grep "^${pgroup}$" > /dev/null 243 then 244 debug_message "Validate - Primary group for userid ${USERID} is mqm" 245 else 246 if /usr/bin/getent group mqm | /usr/bin/awk -F: '{print $4}' | \ 247 /usr/bin/grep ${USERID} > /dev/null 248 then 249 debug_message "Validate - Secondary group for userid ${USERID} is mqm" 250 else 251 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 252 "Validate - Userid %s is not a member of group mqm" \ 253 "${USERID}" 254 rc=1 255 fi 256 fi 257 else 258 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 259 "Validate - Userid %s is not a valid userid" \ 260 "${USERID}" 261 rc=1 262 fi 263 fi 264 265 if [ -d /opt/mqm -a -d /var/mqm ] 266 then 267 debug_message "Validate - WebSphere MQ file systems ok" 268 else 269 # SCMSGS 270 # @explanation 271 # The required WebSphere MQ file systems, /opt/mqm and /var/mqm are 272 # not defined. 273 # @user_action 274 # Ensure that /opt/mqm and /var/mqm are defined. 275 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 276 "Validate - WebSphere MQ file systems not defined" 277 rc=1 278 fi 279 280 debug_message "Function: validate - End" 281 return ${rc} 282 } 283 284 start_qmgr() 285 { 286 debug_message "Function: start_qmgr - Begin" 287 ${SET_DEBUG} 288 289 /usr/bin/rm ${LOGFILE} 290 291 if [ "${CALLER}" = "GDS" ] 292 then 293 # Turn off PMF restart if ${QMGR} has been manually started 294 check_qmgr debug 295 rc=$? 296 297 if [ "${rc}" -eq 0 ] 298 then 299 /usr/bin/sleep 120 & 300 /usr/cluster/bin/pmfadm -s ${RESOURCEGROUP},${RESOURCE},0.svc 301 302 # SCMSGS 303 # @explanation 304 # The specified WebSphere MQ queue manager has been started 305 # manually. 306 # @user_action 307 # None required. Informational message. 308 scds_syslog -p daemon.notice -t $(syslog_tag) -m \ 309 "start_qmgr - WebSphere MQ %s was manually started" \ 310 "${QMGR}" 311 312 return 0 313 fi 314 fi 315 316 SC3_XARM= 317 318 if [ ! -z ${DB2INSTANCE} ]; then 319 SC3_XARM="env DB2INSTANCE=${DB2INSTANCE}" 320 fi 321 322 if [ ! -z ${ORACLE_HOME} ]; then 323 SC3_XARM="$SC3_XARM env ORACLE_HOME=${ORACLE_HOME}" 324 fi 325 326 if [ ! -z ${ORACLE_SID} ]; then 327 SC3_XARM="$SC3_XARM env ORACLE_SID=${ORACLE_SID}" 328 fi 329 330 if [ "${mqver}" -eq 6 ] 331 then 332 SERVICES=`/usr/bin/echo ${SERVICES} | /usr/bin/tr -s '[:lower:]' '[:upper:]'` 333 if [ "${SERVICES}" = "NO" ] 334 then 335 SERVICES=-ns 336 else 337 SERVICES= 338 fi 339 else 340 SERVICES= 341 fi 342 343 if [ "${CALLER}" = "GDS" ] 344 then 345 /usr/bin/su - ${USERID} -c "${TASK_COMMAND} env SC3_COMMAND=${START_COMMAND} ${SC3_XARM} strmqm ${SERVICES} ${QMGR} ${OUTPUT}" > /dev/null 346 else 347 env SC3_COMMAND=${START_COMMAND} ${SC3_XARM} strmqm ${SERVICES} ${QMGR} > ${LOGFILE} 2>&1 348 rc=$? 349 [ "${rc}" -eq 0 ] && smf_wait_for_online "qmgr NOSU" 350 fi 351 352 rc=$? 353 log_message notice "strmqm rc(${rc})" 354 355 debug_message "Function: start_qmgr - End" 356 return ${rc} 357 } 358 359 check_start() 360 { 361 debug_message "Function: check_start - Begin" 362 ${SET_DEBUG} 363 364 # Allow "wait_for_online" to only test after the 365 # specified method for ${RESOURCE} has finished 366 367 rc=1 368 369 # Here $1 is set when check_start is called from within control_wmqs, e.g. 370 # check_start "start-qmgr stop-qmgr" etc. 371 372 for component in $1 373 do 374 if [ "${CALLER}" = "GDS" ] 375 then 376 if [ -x /sbin/zonename ] 377 then 378 /usr/bin/pgrep -z ${ZONENAME} -f "${component} .*-R ${RESOURCE} " >/dev/null 2>&1 379 else 380 /usr/bin/pgrep -u root -f "${component} .*-R ${RESOURCE} " >/dev/null 2>&1 381 fi 382 else 383 # Here we are being called by SMF where ${component} has already been broken down, 384 # i.e. The SMF start method uses "control_wmqs start qmgr ${RESOURCE}" and not 385 # start-qmgr which is being passed as $1, therefore we need to amend ${component}. 386 # 387 # Note, that ${RESOURCE}, when called by SMF, reflects the FMRI which when using a 388 # failover zone is the same as the Sun Cluster resource name. 389 390 component=`/usr/bin/echo ${component} | /usr/bin/tr "-" " "` 391 /usr/bin/pgrep -u ${USERID} -f "${component} ${RESOURCE} " >/dev/null 2>&1 392 fi 393 394 rc=$? 395 396 if [ "${rc}" -eq 0 ] 397 then 398 rc=100 399 break 400 else 401 rc=0 402 fi 403 done 404 405 debug_message "Function: check_start - End" 406 return ${rc} 407 } 408 409 check_qmgr() 410 { 411 # create_tdq does the following 412 # MQCONN - Connect to ${QMGR} 413 # MQOPEN - Open a temporary dynamic queue 414 # MQPUT1 - Put a test message to that queue 415 # MQDISC - Disconnect from ${QMGR} 416 417 debug_message "Function: check_qmgr - Begin" 418 ${SET_DEBUG} 419 420 NOSU=$1 421 LEVEL=notice 422 423 # start_qmgr() also calls this function when the resource is being started, 424 # however when this happens "debug" is passed to us, simply so that we don't 425 # output a notice message when the resource is being started. 426 427 [ "${NOSU}" = "debug" ] && LEVEL=debug 428 429 # When called by GDS or via the sczsmf probe component we must "su" as both of 430 # those environments are running as root. However this function is also called 431 # when the SMF FMRI is enabled, either by sczsmf start component which issues 432 # svcadm enable -t <FMRI>. In this environment we are running as ${USERID}, so 433 # we must not "su" again. 434 435 if [ "${NOSU}" != "NOSU" ] 436 then 437 check_qmgr_status=`/usr/bin/su ${USERID} -c "${MYDIR}/../mgr/bin/create_tdq ${QMGR}"` 438 else 439 check_qmgr_status=`${MYDIR}/../mgr/bin/create_tdq ${QMGR}` 440 fi 441 442 rc=$? 443 if [ "${rc}" -ne 0 ] 444 then 445 # SCMSGS 446 # @explanation 447 # The Queue Manager check has failed. 448 # @user_action 449 # None required. Informational message. 450 scds_syslog -p daemon.${LEVEL} -t $(syslog_tag) -m \ 451 "check_qmgr - <%s>" \ 452 "${check_qmgr_status}" 453 rc=100 454 fi 455 456 debug_message "Function: check_qmgr - End" 457 return ${rc} 458 } 459 460 stop_qmgr() 461 { 462 debug_message "Function: stop_qmgr - Begin" 463 ${SET_DEBUG} 464 465 # For WMQ v6 queue managers, if the Listener (runmqlsr) is started before the 466 # queue manager (regardless if the queue manager was started with -ns) then runmqlsr 467 # starts process amqzmgr0 (Process Controller). 468 # 469 # Because of this we ignore amqzmgr0 when stopping the queue manager, as amqzmgr0 470 # gets stopped when runmqlsr is stopped. 471 472 if [ "${mqver}" -eq 6 ] 473 then 474 IGNORE="| /usr/bin/grep -v amqzmgr0" 475 else 476 IGNORE= 477 fi 478 479 if [ "${CALLER}" = "SMF" ] 480 then 481 IGNORE="${IGNORE} | /usr/bin/grep -v control_wmqs" 482 fi 483 484 for func in endmqm_immediate \ 485 endmqm_preemptive \ 486 cleanup_qmgr 487 do 488 case ${func} in 489 endmqm_immediate) ((LOOP_TIME=${STOP_TIMEOUT} *40/100));; 490 endmqm_preemptive) ((LOOP_TIME=${STOP_TIMEOUT} *30/100));; 491 cleanup_qmgr) ((LOOP_TIME=${STOP_TIMEOUT} *5/100));; 492 esac 493 494 # Bail out of running endmqm if we've lost amqzxma0 495 496 if [ "${func}" = "endmqm_immediate" -o "${func}" = "endmqm_preemptive" ] 497 then 498 if query_pids "-w amqzxma0" 499 then 500 if [ "${func}" = "endmqm_immediate" ] 501 then 502 run_endmqm -i 503 else 504 run_endmqm -p 505 fi 506 507 # Test if any ${QMGR} pids are still running 508 509 while (( ${LOOP_TIME} > 0 )) 510 do 511 if query_pids "-v runmqlsr ${IGNORE}" 512 then 513 /usr/bin/sleep 1 514 LOOP_TIME=`expr ${LOOP_TIME} - 1` 515 else 516 break 517 fi 518 done 519 520 # Log any endmqm messages 521 log_message notice endmqm 522 523 # Test if ${func} used all it's allocated time and ignore 524 # any runmqlsr pids. 525 526 if ! query_pids "-v runmqlsr ${IGNORE}" 527 then 528 break 529 fi 530 fi 531 else 532 ${func} 533 fi 534 done 535 536 debug_message "Function: stop_qmgr - End" 537 return 0 538 } 539 540 run_endmqm() 541 { 542 debug_message "Function: run_endmqm - Begin" 543 ${SET_DEBUG} 544 545 OPTION=${1} 546 query_pids "-w runmqsc" 547 548 for i in ${pids} 549 do 550 /usr/bin/kill -9 ${i} 551 debug_message "MQSC command prompt (runmqsc) for ${QMGR} found and killed" 552 done 553 554 # Allow for multiple databases that can be included within global units of work. 555 556 SC3_XARM= 557 558 if [ ! -z ${DB2INSTANCE} ]; then 559 SC3_XARM="env DB2INSTANCE=${DB2INSTANCE}" 560 fi 561 562 if [ ! -z ${ORACLE_HOME} ]; then 563 SC3_XARM="${SC3_XARM} env ORACLE_HOME=${ORACLE_HOME}" 564 fi 565 566 if [ ! -z ${ORACLE_SID} ]; then 567 SC3_XARM="${SC3_XARM} env ORACLE_SID=${ORACLE_SID}" 568 fi 569 570 # 571 # See IBM Technote 1159674 for MQCHL_NO_TERM_FFST 572 # 573 # Turns off FFSTs when a channel job dies before the channel status 574 # table is updated. It will not affect any other FDCs being generated 575 # 576 577 if [ "${CALLER}" = "GDS" ] 578 then 579 /usr/bin/su - ${USERID} -c "${TASK_COMMAND} env MQCHL_NO_TERM_FFST=1 env SC3_COMMAND=${STOP_COMMAND} ${SC3_XARM} endmqm ${OPTION} ${QMGR} ${OUTPUT} &" > /dev/null 580 else 581 env MQCHL_NO_TERM_FFST=1 env SC3_COMMAND=${STOP_COMMAND} ${SC3_XARM} endmqm ${OPTION} ${QMGR} > ${LOGFILE} 2>&1 & 582 fi 583 584 debug_message "Function: run_endmqm - End" 585 } 586 587 cleanup_qmgr() 588 { 589 debug_message "Function: cleanup_qmgr - Begin" 590 ${SET_DEBUG} 591 592 if [ "${mqver}" -eq 6 ] 593 then 594 pids="amqzmuc0 amqzxma0 amqzfuma amqzlaa0 amqzlsa0 amqzmur0 amqrmppa amqrrmfa amqzdmaa runmqchi amqpcsea" 595 IGNORE="-v runmqlsr | /usr/bin/grep -v amqzmgr0 " 596 else 597 pids="amqhasmx amqharmx amqzllp0 amqzlaa0 amqzfuma amqzxma0 amqrrmfa amqzdmaa" 598 IGNORE="-v runmqlsr " 599 fi 600 601 for pid in ${pids} 602 do 603 query_pids "-w ${pid}" 604 [ "${pids}" ] && /usr/bin/kill -9 ${pids} 605 done 606 607 # Cleanup any other pids that may have been missed, while ignoring 608 # any runmqlsr processes. 609 610 if [ "${CALLER}" = "SMF" ] 611 then 612 IGNORE="${IGNORE} | /usr/bin/grep -v control_wmqs" 613 fi 614 615 query_pids "${IGNORE}" 616 [ "${pids}" ] && /usr/bin/kill -9 ${pids} 617 618 # If we're in this part of the code then either some critical WMQ processes have failed or 619 # the allocated time to stop the queue manager (immediate|preemptive) has expired. In this 620 # case we follow a specific order to kill processes (as above). 621 # 622 # However, whatever causes this part of the code to be run, the queue manager may incur an 623 # unexpected error (RC 71) and perhaps "AMQ8041 The queue manager cannot be restarted or 624 # deleted because processes, that were previosly connected, are still running." 625 # 626 # In this regard to try and avoid any unexpected errors, all associated listeners (runmqlsr) 627 # for this queue manager are stopped and will be restarted by the lsr componet, if required. 628 # 629 # Note: Ending all the associated queue manager listeners will only occur if the queue 630 # manager used the allocated stop time or critical WMQ processes failed, as detailed above. 631 632 if [ "${CALLER}" = "GDS" ] 633 then 634 /usr/bin/su - ${USERID} -c "${TASK_COMMAND} endmqlsr -w -m ${QMGR} ${OUTPUT}" > /dev/null 635 else 636 endmqlsr -w -m ${QMGR} > ${LOGFILE} 2>&1 637 fi 638 639 log_message notice endmqlsr 640 641 # SCMSGS 642 # @explanation 643 # All the WebSphere MQ processess for the specified Queue Manager have 644 # been stopped. 645 # @user_action 646 # None required. Informational message. 647 scds_syslog -p daemon.notice -t $(syslog_tag) -m \ 648 "All WebSphere MQ (%s) processes stopped" \ 649 "${QMGR}" 650 651 debug_message "Function: cleanup_qmgr - End" 652 } 653 654 cleanup_ipc() 655 { 656 # Only if ${CLEANUP} is YES 657 CLEANUP=`/usr/bin/echo ${CLEANUP} | /usr/bin/tr -s '[:lower:]' '[:upper:]'` 658 [ "${CLEANUP}" != "YES" ] && return 0 659 660 debug_message "Function: cleanup_ipc - Begin" 661 ${SET_DEBUG} 662 663 # Cleanup any IPC shared memory segments however only if 664 # 665 # - The shared memory segment(s) are owned by 666 # OWNER=mqm and GROUP=mqm 667 # - The shared memory has no attached processes 668 # - The CPID and LPID processes are not running 669 670 flag= 671 # Allow some time for IPC to cleanup normally 672 /usr/bin/sleep 2 673 674 if [ "${DEBUG}" = "${RESOURCE}" -o "${DEBUG}" = "ALL" ] 675 then 676 debug_message "IPC Status BEFORE removal of non-attached segments created by user mqm" 677 678 if [ -x /sbin/zonename ] 679 then 680 /usr/bin/ipcs -mcopbZ | /usr/bin/grep " ${ZONENAME}$" > ${LOGFILE} 681 else 682 /usr/bin/ipcs -mcopb > ${LOGFILE} 683 fi 684 685 log_message debug ipcs 686 fi 687 688 if [ -x /sbin/zonename ] 689 then 690 # Perform cleanup on a Solaris 10 node 691 692 /usr/bin/ipcs -mcopbZ | /usr/bin/grep " ${ZONENAME}$" | /usr/bin/awk ' \ 693 {if (NF == 13 && $5 == "mqm" && $6 == "mqm" && $9 == 0 ) print $2,$11,$12; else \ 694 if (NF == 12 && $4 == "mqm" && $5 == "mqm" && $8 == 0 ) print $1,$10,$11 }' | \ 695 while read SHMID CPID LPID 696 do 697 if /usr/bin/ps -p ${LPID} -o zone | /usr/bin/grep " ${ZONENAME}$" > /dev/null 698 then 699 debug_message "WebSphere MQ SHMID: ${SHMID} - LPID ${LPID} is running" 700 else 701 if /usr/bin/ps -p ${CPID} -o zone | /usr/bin/grep " ${ZONENAME}$" > /dev/null 702 then 703 debug_message "WebSphere MQ SHMID: ${SHMID} - CPID ${CPID} is running" 704 else 705 SHMID=`/usr/bin/echo ${SHMID} | /usr/bin/tr 'm' ' '` 706 707 # As the initial ipcs -mcopbZ is only a snapshot in time, the queue manager 708 # may have already cleaned up. Therefore the following attempt to remove a 709 # shared memory segment may fail with "not found". To prevent misleading 710 # console messages stdout/stderr is redirected to ${LOGFILE} via ${OUTPUT}, 711 # refer to set_redirection() for more details. ${LOGFILE} is not output to 712 # syslog and instead is overwritten by other functions that use ${OUTPUT}. 713 714 if [ "${CALLER}" = "GDS" ] 715 then 716 /usr/bin/su mqm -c "/usr/bin/ipcrm -z ${ZONENAME} -m ${SHMID} ${OUTPUT}" > /dev/null 717 else 718 /usr/bin/ipcrm -z ${ZONENAME} -m ${SHMID} ${OUTPUT} 719 fi 720 721 debug_message "WebSphere MQ SHMID: ${SHMID} - removed" 722 723 flag=deleted 724 fi 725 fi 726 done 727 else 728 # Perform cleanup on a pre-Solaris 10 node 729 730 /usr/bin/ipcs -mcopb | /usr/bin/awk ' \ 731 {if (NF == 12 && $5 == "mqm" && $6 == "mqm" && $9 == 0 ) print $2,$11,$12; else \ 732 if (NF == 11 && $4 == "mqm" && $5 == "mqm" && $8 == 0 ) print $1,$10,$11 }' | \ 733 while read SHMID CPID LPID 734 do 735 if /usr/bin/ps -p ${LPID} > /dev/null 736 then 737 debug_message "WebSphere MQ SHMID: ${SHMID} - LPID ${LPID} is running" 738 else 739 if /usr/bin/ps -p ${CPID} > /dev/null 740 then 741 debug_message "WebSphere MQ SHMID: ${SHMID} - CPID ${CPID} is running" 742 else 743 SHMID=`/usr/bin/echo ${SHMID} | /usr/bin/tr 'm' ' '` 744 745 /usr/bin/su mqm -c "/usr/bin/ipcrm -m ${SHMID} ${OUTPUT}" > /dev/null 746 debug_message "WebSphere MQ SHMID: ${SHMID} - removed" 747 748 flag=deleted 749 fi 750 fi 751 done 752 fi 753 754 if [ "${flag}" ]; then 755 # SCMSGS 756 # @explanation 757 # All the WebSphere MQ shared memory segments that were not being 758 # used have been removed. 759 # @user_action 760 # None required. Informational message. 761 scds_syslog -p daemon.notice -t $(syslog_tag) -m \ 762 "All WebSphere MQ non-attached IPC shared memory segments removed" 763 fi 764 765 debug_message "IPC Status AFTER removal of non-attached segments created by user mqm" 766 767 if [ "${DEBUG}" = "${RESOURCE}" -o "${DEBUG}" = "ALL" ] 768 then 769 if [ -x /sbin/zonename ] 770 then 771 /usr/bin/ipcs -mcopbZ | /usr/bin/grep " ${ZONENAME}$" > ${LOGFILE} 772 else 773 /usr/bin/ipcs -mcopb > ${LOGFILE} 774 fi 775 776 log_message debug ipcs 777 fi 778 779 debug_message "Function: cleanup_ipc - End" 780 return 0 781 } 782 783 start_lsr() 784 { 785 debug_message "Function: start_lsr - Begin" 786 ${SET_DEBUG} 787 788 /usr/bin/rm ${LOGFILE} 789 790 PORT_LIST=`/usr/bin/echo ${PORT} | tr '/' ' '` 791 792 ipaddr="" 793 794 if [ "${mqver}" -eq 6 ] 795 then 796 [ ${IPADDR} ] && ipaddr="-i ${IPADDR}" 797 fi 798 799 for port in ${PORT_LIST} 800 do 801 if [ "${CALLER}" = "GDS" ] 802 then 803 /usr/bin/su - ${USERID} -c "${TASK_COMMAND} runmqlsr -t tcp -p ${port} ${ipaddr} -b ${BACKLOG} -m ${QMGR} ${OUTPUT} &" > /dev/null 804 else 805 runmqlsr -t tcp -p ${port} ${ipaddr} -b ${BACKLOG} -m ${QMGR} > ${LOGFILE} 2>&1 & 806 fi 807 808 # SCMSGS 809 # @explanation 810 # The specified WebSphere MQ Listener has been started. 811 # @user_action 812 # None required. Informational message. 813 scds_syslog -p daemon.notice -t $(syslog_tag) -m \ 814 "WebSphere MQ Listener for port %s started" \ 815 "${port}" 816 817 check_output 818 log_message error runmqlsr 819 done 820 821 debug_message "Function: start_lsr - End" 822 return 0 823 } 824 825 stop_lsr() 826 { 827 debug_message "Function: stop_lsr - Begin" 828 ${SET_DEBUG} 829 830 # To accommodate multiple port entries within a resource we must 831 # kill each runmqlsr/port associated with this resource instead 832 # of issuing endmqlsr which would stop ALL runmqlsr programs for 833 # this ${QMGR}, as there maybe multiple SC listener resources with 834 # different port numbers. 835 836 PORT_LIST=`/usr/bin/echo ${PORT} | tr '/' ' '` 837 838 for port in ${PORT_LIST} 839 do 840 query_pids "-w runmqlsr | /usr/bin/grep '\\-p ${port}' " 841 rc=$? 842 843 if [ "${rc}" -eq 0 ] 844 then 845 [ "${pids}" ] && /usr/bin/kill -9 ${pids} 846 847 # SCMSGS 848 # @explanation 849 # The specified WebSphere MQ Listener has been stopped. 850 # @user_action 851 # None required. Informational message. 852 scds_syslog -p daemon.notice -t $(syslog_tag) -m \ 853 "WebSphere MQ Listener for port %s stopped" \ 854 "${port}" 855 fi 856 done 857 858 debug_message "Function: stop_lsr - End" 859 } 860 861 check_lsr() 862 { 863 debug_message "Function: check_lsr - Begin" 864 ${SET_DEBUG} 865 866 # For multiple port entries within a resource we need to 867 # check each runmqlsr/port combination and restart any 868 # failed runmqlsr/port programs from the PROBE method. 869 # A conventional restart (STOP/START) would restart all 870 # rummqlsr programs associated with this resource. 871 872 PORT_LIST=`/usr/bin/echo ${PORT} | tr '/' ' '` 873 874 ipaddr="" 875 876 if [ "${mqver}" -eq 6 ] 877 then 878 [ ${IPADDR} ] && ipaddr="-i ${IPADDR}" 879 fi 880 881 # If a single port is used by the runmqlsr resource then we do not 882 # want the resource restarted by the PROBE method. Instead the default 883 # restart behaviour is required. 884 885 SINGLE_PORT=`/usr/bin/echo ${PORT_LIST} | /usr/bin/awk '{if (NF == 1) print $1}'` 886 887 if [ "${SINGLE_PORT}" ] 888 then 889 query_pids "-w runmqlsr | /usr/bin/grep '\\-p ${SINGLE_PORT}' " 890 rc=$? 891 else 892 rc=0 893 894 for port in ${PORT_LIST} 895 do 896 query_pids "-w runmqlsr | /usr/bin/grep '\\-p ${port}' " 897 rc_lsr=$? 898 899 if [ "${rc_lsr}" -ne 0 ] 900 then 901 # When called by GDS or via the sczsmf probe component we must "su" as both of 902 # those environments are running as root. 903 904 /usr/bin/su - ${USERID} -c "${TASK_COMMAND} runmqlsr -t tcp -p ${port} ${ipaddr} -b ${BACKLOG} -m ${QMGR} ${OUTPUT} &" > /dev/null 905 906 # SCMSGS 907 # @explanation 908 # The specified WebSphere MQ Listener has been restarted. 909 # @user_action 910 # None required. Informational message. 911 scds_syslog -p daemon.notice -t $(syslog_tag) -m \ 912 "WebSphere MQ Listener for port %s restarted." \ 913 "${port}" 914 915 check_output 916 log_message error runmqlsr 917 fi 918 done 919 fi 920 921 [ "${rc}" -ne 0 ] && rc=100 922 923 debug_message "Function: check_lsr - End" 924 return ${rc} 925 } 926 927 check_output() 928 { 929 debug_message "Function: check_output - Begin" 930 ${SET_DEBUG} 931 932 # Log any AMQ error messages found in ${LOGFILE} 933 # log_message only outputs if ${LOGFILE} is not empty 934 935 /usr/bin/sleep 1 936 /usr/bin/grep AMQ ${LOGFILE} | /usr/bin/tee ${LOGFILE} > /dev/null 937 rc=0; [ -s "${LOGFILE}" ] && rc=1 938 939 debug_message "Function: check_output - End" 940 return ${rc} 941 } 942 943 check_restart() 944 { 945 debug_message "Function: check_restart - Begin" 946 ${SET_DEBUG} 947 948 # Preserve the restart dependency check 949 flag= 950 rc=1 951 952 while [ "${rc}" -ne 0 ] 953 do 954 if [ "${mqver}" -eq 6 ] 955 then 956 query_pids "-c -E 'amqzmuc0|amqzxma0'" 957 else 958 query_pids "-c -E 'amqzxma0|amqhasmx'" 959 fi 960 961 if [ "${pids}" -eq 2 ] 962 then 963 if [ "${CALLER}" = "GDS" ] 964 then 965 /usr/bin/echo "ping qmgr" | /usr/bin/su - ${USERID} -c "runmqsc ${QMGR} ${OUTPUT}" > /dev/null 966 else 967 /usr/bin/echo "ping qmgr" | runmqsc ${QMGR} > ${LOGFILE} 2>&1 968 fi 969 970 rc=$? 971 972 if [ "${rc}" -ne 0 ] 973 then 974 # Return 100 for chi, csv and trm test methods 975 if [ "${METHOD}" = "test" ] 976 then 977 return 100 978 fi 979 980 if [ "${flag}" = "set" ] 981 then 982 flag=set 983 # SCMSGS 984 # @explanation 985 # A WebSphere MQ component is waiting for the Queue 986 # Manager. 987 # @user_action 988 # None required. Informational message. 989 scds_syslog -p daemon.notice -t $(syslog_tag) -m \ 990 "Waiting for WebSphere MQ Queue Manager" 991 fi 992 /usr/bin/sleep 5 993 fi 994 else 995 /usr/bin/sleep 5 996 rc=1 997 fi 998 done 999 1000 if [ "${METHOD}" != "test" ] 1001 then 1002 # SCMSGS 1003 # @explanation 1004 # The Queue Manager is now available. 1005 # @user_action 1006 # None required. Informational message. 1007 scds_syslog -p daemon.notice -t $(syslog_tag) -m \ 1008 "WebSphere MQ Queue Manager available" 1009 fi 1010 1011 debug_message "Function: check_restart - End" 1012 } 1013 1014 start_chi() 1015 { 1016 debug_message "Function: start_chi - Begin" 1017 ${SET_DEBUG} 1018 1019 /usr/bin/rm ${LOGFILE} 1020 1021 check_restart 1022 1023 if [ "${CALLER}" = "GDS" ] 1024 then 1025 /usr/bin/su - ${USERID} -c "${TASK_COMMAND} runmqchi -m ${QMGR} -q ${INITQNAME} ${OUTPUT} &" > /dev/null 1026 else 1027 runmqchi -m ${QMGR} -q ${INITQNAME} > ${LOGFILE} 2>&1 & 1028 fi 1029 1030 # To avoid "AMQ9509: Program cannot open queue manager object." 1031 # the start is retried every 5% of START_TIMEOUT.