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 2006 Sun Microsystems, Inc. All rights reserved. 24 # Use is subject to license terms. 25 # 26 #ident "@(#)functions.ksh 1.6 07/08/07 SMI" 27 # 28 29 PKG=SUNWscmqi 30 MYNAME=`basename $0` 31 MYDIR=`dirname $0` 32 MYTMPDIR=/var/tmp 33 LOGFILE=${MYTMPDIR}/${RESOURCE}_logfile 34 TASK_COMMAND="" 35 PATTERN="\<${BROKER}\>" 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 ${MQSIUSER} | /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 # If being run on Solaris 10, query_pids() matches the 130 # correct zonename, otherwise zones are ignored for 131 # pre-Solaris 10 systems. 132 # 133 # query_pids() matches against the correct broker name 134 # and will exclude "broker.name" names, i.e. exclude 135 # a similar broker name that uses the "." notation. 136 137 rc=1 138 139 EXCLUDE= 140 PROCESS= 141 [ "${1}" ] && PROCESS="| /usr/xpg4/bin/grep ${1}" 142 143 # If ${BROKER} is not a "broker.name" notation then 144 # exclude any ${BROKER}"." and ${BROKER}"!" entries 145 146 if ! /usr/bin/echo ${BROKER} | /usr/bin/grep '\.' > /dev/null 147 then 148 EXCLUDE="| /usr/xpg4/bin/grep -v -E '${BROKER}\.|${BROKER}\!'" 149 fi 150 151 if [ -x /sbin/zonename ] 152 then 153 pids=`/usr/bin/ps -u ${MQSIUSER} -o pid,args,zone | /usr/bin/grep " ${ZONENAME}$" | \ 154 eval /usr/xpg4/bin/grep -E '${PATTERN}' ${EXCLUDE} ${PROCESS} | /usr/bin/awk '{print $1}'` 155 else 156 pids=`/usr/bin/ps -u ${MQSIUSER} -o pid,args | \ 157 eval /usr/xpg4/bin/grep -E '${PATTERN}' ${EXCLUDE} ${PROCESS} | /usr/bin/awk '{print $1}'` 158 fi 159 160 [ "${pids}" ] && rc=0 161 162 debug_message "Function: query_pids - End" 163 return ${rc} 164 } 165 166 validate() 167 { 168 debug_message "Function: validate - Begin" 169 ${SET_DEBUG} 170 171 rc=0 172 173 if /usr/bin/cat /etc/group | /usr/bin/awk -F: '{print $1}' | /usr/bin/grep mqbrkrs > /dev/null 174 then 175 debug_message "Validate - Group mqbrkrs exists" 176 else 177 # SCMSGS 178 # @explanation 179 # The WebSphere MQ Broker resource failed to validate that the 180 # group mqbrkrs exists. 181 # @user_action 182 # Ensure that the group mqbrkrs exists. 183 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 184 "Validate - Group mqbrkrs does not exist" 185 rc=1 186 fi 187 188 pgroup=`/usr/bin/grep "^${MQSIUSER}:" /etc/passwd | /usr/bin/awk -F: '{print $4}'` 189 190 if [ ! -z ${pgroup} ] 191 then 192 if /usr/bin/cat /etc/group | /usr/bin/awk -F: '{ if ($1 == "mqm") print $3}' | /usr/bin/grep "^${pgroup}$" > /dev/null 193 then 194 debug_message "Validate - Primary group for userid ${MQSIUSER} is mqm" 195 else 196 if /usr/bin/cat /etc/group | /usr/bin/awk -F: '{ if ($1 == "mqm") print $4}' | /usr/bin/grep ${MQSIUSER} > /dev/null 197 then 198 debug_message "Validate - Secondary group for userid ${MQSIUSER} is mqm" 199 else 200 # SCMSGS 201 # @explanation 202 # The specified userid is not a member of group mqm. 203 # @user_action 204 # The specified user must be a member of grouo mqm. 205 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 206 "Validate - Userid %s is not a member of group mqm" \ 207 "${MQSIUSER}" 208 rc=1 209 fi 210 fi 211 212 if /usr/bin/cat /etc/group | /usr/bin/awk -F: '{ if ($1 == "mqbrkrs") print $3}' | /usr/bin/grep "^${pgroup}$" > /dev/null 213 then 214 debug_message "Validate - Primary group for userid $MQSIUSER is mqbrkrs" 215 else 216 if /usr/bin/cat /etc/group | /usr/bin/awk -F: '{ if ($1 == "mqbrkrs") print $4}' | /usr/bin/grep ${MQSIUSER} > /dev/null 217 then 218 debug_message "Validate - Secondary group for userid ${MQSIUSER} is mqbrkrs" 219 else 220 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 221 "Validate - Userid %s is not a member of group mqm" \ 222 "${MQSIUSER}" 223 rc=1 224 fi 225 fi 226 else 227 # SCMSGS 228 # @explanation 229 # The specified userid does not exist within /etc/passwd. 230 # @user_action 231 # Ensure that the userid has been added. 232 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 233 "Validate - Userid %s is not a valid userid" \ 234 "${MQSIUSER}" 235 rc=1 236 fi 237 238 if [ -d /opt/mqsi -a -d /var/mqsi ] 239 then 240 debug_message "Validate - WebSphere MQ Broker file systems ok" 241 else 242 # SCMSGS 243 # @explanation 244 # The WebSphere MQ Broker file systems (/opt/mqsi and /var/mqsi) 245 # are not defined. 246 # @user_action 247 # Ensure that the WebSphere MQ Broker file systems are defined 248 # correctly. 249 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 250 "Validate - WebSphere MQ Broker file systems not defined" 251 rc=1 252 fi 253 254 debug_message "Function: validate - End" 255 return ${rc} 256 } 257 258 check_start() 259 { 260 debug_message "Function: check_start - Begin" 261 ${SET_DEBUG} 262 263 # Allow "wait_for_online" to only test after the 264 # specified method for ${RESOURCE} has finished. 265 266 rc=1 267 268 # Here $1 is set when check_start is called from within control-wmqi, e.g. 269 # check_start "start-broker stop-broker" or check_start "start-uns stop-uns" 270 271 for component in $1 272 do 273 if [ "${CALLER}" = "GDS" ] 274 then 275 if [ -x /sbin/zonename ] 276 then 277 /usr/bin/pgrep -z ${ZONENAME} -f "${component} .*-R ${RESOURCE} " >/dev/null 2>&1 278 else 279 /usr/bin/pgrep -u root -f "${component} .*-R ${RESOURCE} " >/dev/null 2>&1 280 fi 281 fi 282 283 rc=$? 284 285 if [ "${rc}" -eq 0 ] 286 then 287 rc=100 288 break 289 else 290 rc=0 291 fi 292 done 293 294 debug_message "Function: check_start - End" 295 return ${rc} 296 } 297 298 start_broker() 299 { 300 # Start the Broker 301 # 302 # Here, we test for the existence of some semaphores 303 # 304 # (a) MQSeriesIntegrator2BrokerResourceTableLockSempahore 305 # (b) MQSeriesIntegrator2RetainedPubsTableLockSemaphore 306 # 307 # If either (a) or (b) exists and their respective 308 # semaphore id is not present on that node then we remove 309 # that lock file entry. This prevents 310 # 311 # (a) Execution Group termination on startup with BIP2123 312 # (b) bipbroker termination on startup with BIP2088 313 # 314 315 debug_message "Function: start_broker - Begin" 316 ${SET_DEBUG} 317 318 /usr/bin/rm ${LOGFILE} 319 320 # Test the MQSI Semaphores 321 322 for semaphore in BrokerResourceTableLockSempahore RetainedPubsTableLockSemaphore 323 do 324 if [ -r /var/mqsi/locks/MQSeriesIntegrator2${semaphore} ] 325 then 326 semid_with_zeros=`/usr/bin/cat /var/mqsi/locks/MQSeriesIntegrator2${semaphore}` 327 semid=`expr $semid_with_zeros / 1` 328 329 if /usr/bin/ipcs -s | /usr/bin/grep $semid > /dev/null 330 then 331 continue 332 else 333 # SCMSGS 334 # @explanation 335 # The WebSphere Broker fault monitor checks to see if 336 # MQSeriesIntegrator2BrokerResourceTableLockSempahore or 337 # MQSeriesIntegrator2RetainedPubsTableLockSemaphore exists 338 # within /var/mqsi/locks and that their respective 339 # semaphore id exists. 340 # @user_action 341 # No user action is needed. If either MQSeriesIntegrator2%s 342 # file exists without an IPC semaphore entry, then the 343 # MQSeriesIntegrator2%s file is deleted. This prevents (a) 344 # Execution Group termination on startup with BIP2123 and 345 # (b) bipbroker termination on startup with BIP2088. 346 scds_syslog -p daemon.notice -t $(syslog_tag) -m \ 347 "MQSeriesIntegrator2%s exists without an IPC semaphore entry" \ 348 "${semaphore}" 349 350 # SCMSGS 351 # @explanation 352 # The WebSphere Broker fault monitor checks to see if 353 # MQSeriesIntegrator2BrokerResourceTableLockSempahore or 354 # MQSeriesIntegrator2RetainedPubsTableLockSemaphore exists 355 # within /var/mqsi/locks and that their respective 356 # semaphore id exists. 357 # @user_action 358 # No user action is needed. If either MQSeriesIntegrator2%s 359 # file exists without an IPC semaphore entry, then the 360 # MQSeriesIntegrator2%s file is deleted. This prevents (a) 361 # Execution Group termination on startup with BIP2123 and 362 # (b) bipbroker termination on startup with BIP2088. 363 scds_syslog -p daemon.notice -t $(syslog_tag) -m \ 364 "MQSeriesIntegrator2%s file deleted" \ 365 "${semaphore}" 366 367 /usr/bin/rm /var/mqsi/locks/MQSeriesIntegrator2${semaphore} 368 fi 369 fi 370 done 371 372 if [ "${CALLER}" = "GDS" ] 373 then 374 /usr/bin/su - ${MQSIUSER} -c "${TASK_COMMAND} env SC3_COMMAND=${START_COMMAND} mqsistart ${BROKER} ${OUTPUT}" > /dev/null 375 fi 376 377 rc=$? 378 379 debug_message "Function: start_broker - End" 380 return ${rc} 381 } 382 383 stop_broker() 384 { 385 # Orderly stop of services 386 387 debug_message "Function: stop_broker - Begin" 388 ${SET_DEBUG} 389 390 for func in stop_broker_immediate cleanup_broker 391 do 392 case ${func} in 393 stop_broker_immediate) ((LOOP_TIME=$STOP_TIMEOUT *30/100));; 394 cleanup_broker) ((LOOP_TIME=$STOP_TIMEOUT *5/100));; 395 esac 396 397 # Bail out of running mqsistop if bipservice is lost 398 399 if [ "${func}" = "stop_broker_immediate" ] 400 then 401 if query_pids "-w bipservice" 402 then 403 ${func} 404 405 while (( ${LOOP_TIME} > 0 )) 406 do 407 # Match only broker and effective id and exclude all mqsi<commands> 408 409 if query_pids "-v mqsi" 410 then 411 /usr/bin/sleep 1 412 LOOP_TIME=`expr ${LOOP_TIME} - 1` 413 else 414 break 415 fi 416 done 417 418 # Log any mqsistop messages 419 log_message notice mqsistop 420 421 if ! query_pids "-v mqsi" 422 then 423 break 424 fi 425 fi 426 else 427 ${func} 428 fi 429 done 430 431 debug_message "Function: stop_broker - End" 432 return 0 433 } 434 435 stop_broker_immediate() 436 { 437 # Immediately stop the Broker 438 439 debug_message "Function: stop_broker_immediate - Begin" 440 ${SET_DEBUG} 441 442 if [ "${CALLER}" = "GDS" ] 443 then 444 /usr/bin/su - ${MQSIUSER} -c "${TASK_COMMAND} env SC3_COMMAND=${STOP_COMMAND} mqsistop -i ${BROKER} ${OUTPUT} &" > /dev/null 445 fi 446 447 debug_message "Function: stop_broker_immediate - End" 448 } 449 450 cleanup_broker() 451 { 452 # Cleanup the MQSI Broker 453 454 debug_message "Function: cleanup_broker - Begin" 455 ${SET_DEBUG} 456 457 # query_pids matches against the correct ${BROKER}, which can be 458 # a Broker, UserNameServer or Configuration Manager. Only a matched 459 # process name for the correct ${BROKER} is killed. 460 461 pids="bipservice bipbroker DataFlowEngine biphttplistener bipconfigmgr bipuns" 462 463 for pid in ${pids} 464 do 465 query_pids "-w ${pid}" 466 [ "${pids}" ] && /usr/bin/kill -9 ${pids} 467 done 468 469 # SCMSGS 470 # @explanation 471 # The WebSphere MQ Broker has been successfully stopped. 472 # @user_action 473 # No user action is needed. 474 scds_syslog -p daemon.notice -t $(syslog_tag) -m \ 475 "All WebSphere MQ Broker processes stopped" 476 477 debug_message "Function: cleanup_broker - End" 478 } 479 480 check_broker() 481 { 482 # A simple message flow ensures that the Broker is 483 # working properly. Here we simply test the following 484 # 485 # a. Check $IN_QUEUE and $OUT_QUEUE are valid 486 # b. Empty out $OUT_QUEUE 487 # c. Put a test message to $IN_QUEUE 488 # d. Verify the message flow from $IN_QUEUE to $OUT_QUEUE 489 # 490 # If any of these programs (sc3inq, sc3get, sc3put) fail 491 # then it indicates either a Queue Manager problem or an 492 # Broker problem. In either case we return a restart 493 # request via rc=1. This will cause the Broker to get 494 # restarted. 495 496 debug_message "Function: check_broker - Begin" 497 ${SET_DEBUG} 498 499 rc=0 500 501 # Allow NONE entries for $IN_QUEUE and $OUT_QUEUE 502 503 if [ "${IN_QUEUE}" = "NONE" ] && [ "${OUT_QUEUE}" = "NONE" ] 504 then 505 # Only if bipservice is running 506 507 query_pids "bipservice" 508 rc=$? 509 510 debug_message "Function: check_broker - End" 511 return ${rc} 512 fi 513 514 # Check ${IN_QUEUE} and ${OUT_QUEUE} are valid and empty them out 515 516 for q in ${IN_QUEUE} ${OUT_QUEUE} 517 do 518 if ERR_LOGFILE=`/usr/bin/su ${MQSIUSER} -c "/opt/SUNWscmqi/sib/bin/sc3get ${q} ${QMGR}"` 519 then 520 debug_message "Function: check_broker - sc3get ${q} OK" 521 else 522 log_message error "check_broker - sc3get ${q}" 523 rc=1 524 fi 525 done 526 527 # Put a test message to $IN_QUEUE 528 529 if ERR_LOGFILE=`/usr/bin/echo "Testing message flow from ${IN_QUEUE} to ${OUT_QUEUE}" | \ 530 /usr/bin/su ${MQSIUSER} -c "/opt/SUNWscmqi/sib/bin/sc3put ${IN_QUEUE} ${QMGR}"` 531 then 532 debug_message "Function: check_broker - sc3put ${IN_QUEUE} OK" 533 else 534 log_message error "check_broker - sc3put ${IN_QUEUE}" 535 rc=1 536 fi 537 538 # Verify the message flow from ${IN_QUEUE} to ${OUT_QUEUE} 539 540 # Allow some time for the message flow 541 sleep 2 542 543 if ERR_LOGFILE=`/usr/bin/su ${MQSIUSER} -c "/opt/SUNWscmqi/sib/bin/sc3inq ${OUT_QUEUE} ${QMGR}"` 544 then 545 # Test that Current queue depth = 1 546 CURDEPTH=`/usr/bin/echo ${ERR_LOGFILE} | /usr/bin/awk -F= '{print $2}'` 547 548 if [ "${CURDEPTH}" -eq 1 ] 549 then 550 debug_message "Function: check_broker - sc3inq ${OUT_QUEUE} OK" 551 else 552 # SCMSGS 553 # @explanation 554 # The WebSphere Broker fault monitor checks to see if the 555 # message flow was successful, by inquiring on the current 556 # queue depth for the output queue within the simple message 557 # flow. 558 # @user_action 559 # No user action is needed. The fault monitor displays the 560 # current queue depth until it successfully checks that the 561 # simple message flow has worked. 562 scds_syslog -p daemon.error -t $(syslog_tag) -m \ 563 "check_broker - sc3inq %s CURDEPTH(%s)" \ 564 "${OUT_QUEUE}" "${CURDEPTH}" 565 566 rc=1 567 fi 568 else 569 log_message error "check_broker - sc3inq ${OUT_QUEUE}" 570 rc=1 571 fi 572 573 debug_message "Function: check_broker - End" 574 return ${rc} 575 } 576