Print this page
Split Close
Expand all
Collapse all
          --- /workspace/neilga/ohacds-ids/webrev/usr/src/cmd/ha-services/gds-agents/ids/functions.ksh-
          +++ functions.ksh
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14  # file and include the License file at usr/src/CDDL.txt.
  15   15  # If applicable, add the following below this CDDL HEADER, with the
  16   16  # fields enclosed by brackets [] replaced with your own identifying
  17   17  # information: Portions Copyright [yyyy] [name of copyright owner]
  18   18  #
  19   19  # CDDL HEADER END
  20   20  #
  21   21  # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  22   22  # Use is subject to license terms.
  23   23  #
  24      -#ident   "@(#)functions.ksh 1.4     08/04/29 SMI"
       24 +#ident   "@(#)functions.ksh 1.5     08/05/27 SMI"
  25   25  #
  26   26  
  27   27  PKG=SUNWscids
  28   28  LOGFILE=/var/tmp/${RESOURCE}_logfile
  29   29  TASK_COMMAND=""
  30   30  RESOURCE_PROJECT_NAME=""
  31   31  SCLOGGER=/usr/cluster/lib/sc/scds_syslog
  32   32  LOGGER=/usr/bin/logger
  33   33  
  34   34  syslog_tag()
↓ open down ↓ 10 lines elided ↑ open up ↑
  45   45          else
  46   46             while getopts 'p:t:m' opt
  47   47             do
  48   48                  case "${opt}" in
  49   49                     t) TAG=${OPTARG};;
  50   50                     p) PRI=${OPTARG};;
  51   51                  esac
  52   52             done
  53   53          
  54   54             shift $((${OPTIND} - 1))
  55      -           LOG_STRING=`/usr/bin/printf "$@"`
       55 +           LOG_STRING=$(/usr/bin/printf "$@")
  56   56             ${LOGGER} -p ${PRI} -t ${TAG} ${LOG_STRING}
  57   57          fi
  58   58  }
  59   59  
  60   60  debug_message()
  61   61  {
  62   62          if [ "${DEBUG}" = "${RESOURCE}" -o "${DEBUG}" = "ALL" ]
  63   63          then
  64   64             SET_DEBUG="set -x"
  65   65             DEBUG_TEXT=${1}
↓ open down ↓ 1 lines elided ↑ open up ↑
  67   67             scds_syslog -p daemon.debug -t $(syslog_tag) -m \
  68   68                "%s" "${DEBUG_TEXT}"
  69   69          else
  70   70             SET_DEBUG=
  71   71          fi
  72   72  }
  73   73  
  74   74  log_message()
  75   75  {
  76   76          debug_message "Function: log_message - Begin"
  77      -        {SET_DEBUG}
       77 +        ${SET_DEBUG}
  78   78  
  79   79          if [ -s "${LOGFILE}" ]
  80   80          then
  81   81             PRIORITY=$1
  82   82             HEADER=$2
  83   83  
  84   84             strings ${LOGFILE} > ${LOGFILE}.copy
  85   85  
  86   86             while read MSG_TXT
  87   87             do
↓ open down ↓ 59 lines elided ↑ open up ↑
 147  147             # You must create the group informix.
 148  148             scds_syslog -p daemon.error -t $(syslog_tag) -m \
 149  149                  "Validate - Group informix does not exist"
 150  150             rc=1
 151  151          fi
 152  152  
 153  153          if [ "${USERID}" = "informix" ]
 154  154          then
 155  155             debug_message "Validate - Userid is informix"
 156  156          else
 157      -           pgroup=`/usr/bin/getent passwd ${USERID} | /usr/bin/awk -F: '{print $4}'`
      157 +           pgroup=$(/usr/bin/getent passwd ${USERID} | /usr/bin/awk -F: '{print $4}')
 158  158  
 159  159             if [ -n "${pgroup}" ]
 160  160             then
 161  161                  if /usr/bin/getent group ${pgroup} | /usr/bin/awk -F: '{ if ($1 == "informix") print $3}' | \
 162  162                     /usr/bin/grep "^${pgroup}$" > /dev/null
 163  163                  then
 164  164                     debug_message "Validate - Primary group for userid ${USERID} is informix"
 165  165                  else
 166  166                     if /usr/bin/getent group informix | /usr/bin/awk -F: '{print $4}' | \
 167  167                        /usr/bin/grep ${USERID} > /dev/null
↓ open down ↓ 169 lines elided ↑ open up ↑
 337  337          return ${rc}
 338  338  }
 339  339  
 340  340  start_ids()
 341  341  {
 342  342          debug_message "Function: start_ids - Begin"
 343  343          ${SET_DEBUG}
 344  344  
 345  345          /usr/bin/rm ${LOGFILE} 2> /dev/null
 346  346  
 347      -        if [ "${CALLER}" = "GDS" ]
 348      -        then
 349      -           get_state
 350      -           check_ids debug
 351      -           rc=$?
      347 +        get_state
      348 +        check_ids debug
      349 +        rc=$?
 352  350  
 353      -           # Check_ids will return 0 if
 354      -           # - The Informix Server is running
 355      -           # - No blocked on "MEDIA FAILURE" or "HANG_SYSTEM" exists
      351 +        # Check_ids will return 0 if
      352 +        # - The Informix Server is running
      353 +        # - No blocked on "MEDIA FAILURE" or "HANG_SYSTEM" exists
 356  354  
 357      -           if [ "${rc}" -eq 0 ]
 358      -           then
 359      -                # Turn off PMF restart if ${INFORMIXSERVER} has been manually started
 360      -                /usr/bin/sleep ${START_TIMEOUT} &
 361      -                /usr/cluster/bin/pmfadm -s ${RESOURCEGROUP},${RESOURCE},0.svc
      355 +        if [ "${rc}" -eq 0 ]
      356 +        then
      357 +           # Turn off PMF restart if ${INFORMIXSERVER} has been manually started
      358 +           /usr/bin/sleep ${START_TIMEOUT} &
      359 +           /usr/cluster/bin/pmfadm -s ${RESOURCEGROUP},${RESOURCE},0.svc
 362  360          
 363      -                # SCMSGS
 364      -                # @explanation
 365      -                # The specified Informix Server has been manually started.
 366      -                # @user_action
 367      -                # None required. Informational message.
 368      -                scds_syslog -p daemon.notice -t $(syslog_tag) -m \
 369      -                   "start_ids - Informix Server (%s) was manually started" \
 370      -                   "${INFORMIXSERVER}"
      361 +           # SCMSGS
      362 +           # @explanation
      363 +           # The specified Informix Server has been manually started.
      364 +           # @user_action
      365 +           # None required. Informational message.
      366 +           scds_syslog -p daemon.notice -t $(syslog_tag) -m \
      367 +                "start_ids - Informix Server (%s) was manually started" \
      368 +                "${INFORMIXSERVER}"
 371  369  
 372      -                return 0
 373      -           fi
 374      -
 375      -           /usr/bin/su ${USERID} -c "${TASK_COMMAND} env INFORMIXDIR=${INFORMIXDIR} INFORMIXSERVER=${INFORMIXSERVER} INFORMIXSQLHOSTS=${INFORMIXSQLHOSTS} ONCONFIG=${ONCONFIG} ${INFORMIXDIR}/bin/oninit -y ${OUTPUT} &" > /dev/null
 376      -
 377      -        else
 378      -           env INFORMIXDIR=${INFORMIXDIR} INFORMIXSERVER=${INFORMIXSERVER} INFORMIXSQLHOSTS=${INFORMIXSQLHOSTS} ONCONFIG=${ONCONFIG} ${INFORMIXDIR}/bin/oninit -y > ${LOGFILE} 2>&1 &
 379      -
      370 +           return 0
 380  371          fi
 381  372  
      373 +        /usr/bin/su ${USERID} -c "${TASK_COMMAND} /usr/bin/env INFORMIXDIR=${INFORMIXDIR} INFORMIXSERVER=${INFORMIXSERVER} INFORMIXSQLHOSTS=${INFORMIXSQLHOSTS} ONCONFIG=${ONCONFIG} ${INFORMIXDIR}/bin/oninit -y ${OUTPUT} &" > /dev/null
      374 +
 382  375          rc=$?
 383  376  
 384  377          if [ "${rc}" -eq 0 ]
 385  378          then
 386  379             # SCMSGS
 387  380             # @explanation
 388  381             # The specified Informix Server was started successfully.
 389  382             # @user_action
 390  383             # None required. Informational message.
 391  384             scds_syslog -p daemon.info -t $(syslog_tag) -m \
 392  385                  "start_ids - Informix Server (%s) started rc(%s)" \
 393  386                  "${INFORMIXSERVER}" "${rc}"
 394      -
 395      -           # At present there is no equivalent "wait_for_online" within SMF
 396      -           # therefore we'll perform our own.
 397      -
 398      -           if [ "${CALLER}" = "SMF" ]
 399      -           then
 400      -                smf_wait_for_online
 401      -                rc=$?
 402      -           fi
 403  387          else
 404  388             # SCMSGS
 405  389             # @explanation
 406  390             # The specified Informix Server failed to start.
 407  391             # @user_action
 408  392             # Check the syslog for further messages. If possible the 
 409  393             # Solaris Cluster will attempt to restart the Informix
 410  394             # Server.
 411  395             scds_syslog -p daemon.error -t $(syslog_tag) -m \
 412  396                  "start_ids - Informix Server (%s) failed to start rc(%s)" \
↓ open down ↓ 4 lines elided ↑ open up ↑
 417  401  
 418  402          debug_message "Function: start_ids - End"
 419  403          return ${rc}
 420  404  }
 421  405  
 422  406  check_start()
 423  407  {
 424  408          debug_message "Function: check_start - Begin"
 425  409          ${SET_DEBUG}
 426  410  
 427      -        if [ "${CALLER}" = "GDS" ]
      411 +        if [ -x /sbin/zonename ]
 428  412          then
 429      -           if [ -x /sbin/zonename ]
 430      -           then
 431      -                /usr/bin/pgrep -z ${ZONENAME} -f "$1 .*-R ${RESOURCE} " >/dev/null 2>&1
 432      -           else
 433      -                /usr/bin/pgrep -u root -f "$1 .*-R ${RESOURCE} " >/dev/null 2>&1
 434      -           fi
      413 +           /usr/bin/pgrep -z ${ZONENAME} -f "$1 .*-R ${RESOURCE} " >/dev/null 2>&1
 435  414          else
 436      -                /usr/bin/pgrep -u ${USERID} -f "$1 ${RESOURCE} " >/dev/null 2>&1
      415 +           /usr/bin/pgrep -u root -f "$1 .*-R ${RESOURCE} " >/dev/null 2>&1
 437  416          fi
 438  417  
 439  418          rc=$?
 440  419  
 441  420          debug_message "Function: check_start - End"
 442  421          return ${rc}
 443  422  }
 444  423  
 445  424  get_state()
 446  425  {
↓ open down ↓ 22 lines elided ↑ open up ↑
 469  448          #
 470  449          # The following shows two sample "onstat -" outputs,
 471  450          # Before IDS is started.
 472  451          #
 473  452          #  shared memory not initialized for INFORMIXSERVER 'demo_on'
 474  453          #
 475  454          # After IDS is started.
 476  455          #
 477  456          #  IBM Informix Dynamic Server Version 11.10.FC1       -- On-Line -- Up 01:47:59 -- 29696 Kbytes
 478  457  
 479      -        if [ "${CALLER}" = "GDS" ]
 480      -        then
 481      -           onstat_header=`/usr/bin/su ${USERID} -c "${TASK_COMMAND} env INFORMIXDIR=${INFORMIXDIR} INFORMIXSERVER=${INFORMIXSERVER} INFORMIXSQLHOSTS=${INFORMIXSQLHOSTS} ONCONFIG=${ONCONFIG} ${INFORMIXDIR}/bin/onstat - | /usr/bin/grep ."`
 482      -        else
 483      -           onstat_header=`env INFORMIXDIR=${INFORMIXDIR} INFORMIXSERVER=${INFORMIXSERVER} INFORMIXSQLHOSTS=${INFORMIXSQLHOSTS} ONCONFIG=${ONCONFIG} ${INFORMIXDIR}/bin/onstat - | /usr/bin/grep .`
 484      -        fi
      458 +        onstat_header=$(/usr/bin/su ${USERID} -c "${TASK_COMMAND} /usr/bin/env INFORMIXDIR=${INFORMIXDIR} INFORMIXSERVER=${INFORMIXSERVER} INFORMIXSQLHOSTS=${INFORMIXSQLHOSTS} ONCONFIG=${ONCONFIG} ${INFORMIXDIR}/bin/onstat - | /usr/bin/grep .")
 485  459  
 486  460          if echo ${onstat_header} | /usr/xpg4/bin/grep -q "Informix Dynamic Server"
 487  461          then
 488      -           onstat_mode=`echo ${onstat_header} | /usr/bin/sed -e 's/ -- Up.*$//' -e 's/^.*-- //'`
      462 +           onstat_mode=$(echo ${onstat_header} | /usr/bin/sed -e 's/ -- Up.*$//' -e 's/^.*-- //')
 489  463  
 490  464             if echo ${onstat_header} | /usr/xpg4/bin/grep -q "Blocked:"
 491  465             then
 492      -                onstat_blocked=`echo ${onstat_header} | /usr/bin/sed -e 's/^.*Blocked://'`
      466 +                onstat_blocked=$(echo ${onstat_header} | /usr/bin/sed -e 's/^.*Blocked://')
 493  467             else
 494  468                  onstat_blocked=""
 495  469             fi
 496  470          fi
 497  471  
 498  472          debug_message "Function: get_state - End"
 499  473  }
 500  474  
 501  475  check_ids()
 502  476  {
↓ open down ↓ 73 lines elided ↑ open up ↑
 576  550  
 577  551                  # Any other IDS server modes are treated as a complete failure.
 578  552          
 579  553                  *)                                                      # Unknown modes
 580  554                          rc=100
 581  555                          ;;
 582  556          esac
 583  557  
 584  558          debug_message "check_ids - ${onstat_header}"
 585  559  
 586      -        if [ "${CALLER}" = "GDS" -a "${LEVEL}" != "debug" ]
      560 +        if [ "${LEVEL}" != "debug" ]
 587  561          then
 588  562             # While we tolerate some blocked states we will output a status message
 589  563             # to Solaris Cluster if one is found. Nevertheless the resource remains online.
 590  564  
 591  565             saved_rc=${rc}
 592  566  
 593  567             # Check if GDS is still starting the resource. If GDS start has finished we'll set
 594  568             # the Solaris Cluster resource status with the appropriate Mode and any Blocked state.
 595  569  
 596  570             if ! check_start gds_svc_start
↓ open down ↓ 11 lines elided ↑ open up ↑
 608  582  
 609  583          debug_message "Function: check_ids - End"
 610  584          return ${rc}
 611  585  }
 612  586  
 613  587  stop_ids()
 614  588  {
 615  589          debug_message "Function: stop_ids - Begin"
 616  590          ${SET_DEBUG}
 617  591  
 618      -        MAX_STOP_TIMEOUT=`/usr/bin/expr ${STOP_TIMEOUT} \* 70 \/ 100`
      592 +        MAX_STOP_TIMEOUT=$(/usr/bin/expr ${STOP_TIMEOUT} \* 70 \/ 100)
 619  593          SECONDS=0
 620  594  
 621      -        if [ "${CALLER}" = "GDS" ]
 622      -        then
 623      -           /usr/bin/su ${USERID} -c "${TASK_COMMAND} env INFORMIXDIR=${INFORMIXDIR} INFORMIXSERVER=${INFORMIXSERVER} INFORMIXSQLHOSTS=${INFORMIXSQLHOSTS} ONCONFIG=${ONCONFIG} ${INFORMIXDIR}/bin/onmode -uky ${OUTPUT} &" > /dev/null
      595 +        /usr/bin/su ${USERID} -c "${TASK_COMMAND} /usr/bin/env INFORMIXDIR=${INFORMIXDIR} INFORMIXSERVER=${INFORMIXSERVER} INFORMIXSQLHOSTS=${INFORMIXSQLHOSTS} ONCONFIG=${ONCONFIG} ${INFORMIXDIR}/bin/onmode -uky ${OUTPUT} &" > /dev/null
 624  596  
 625      -        else
 626      -           env INFORMIXDIR=${INFORMIXDIR} INFORMIXSERVER=${INFORMIXSERVER} INFORMIXSQLHOSTS=${INFORMIXSQLHOSTS} ONCONFIG=${ONCONFIG} ${INFORMIXDIR}/bin/onmode -uky  > ${LOGFILE} 2>&1 &
 627      -        fi
 628      -
 629  597          while  [ "${SECONDS}" -lt "${MAX_STOP_TIMEOUT}" ]
 630  598          do
 631  599             get_state
 632  600  
 633  601             if echo ${onstat_header} | /usr/xpg4/bin/grep -q "shared memory not initialized"
 634  602             then
 635  603                  SECONDS=${MAX_STOP_TIMEOUT}
 636  604             else
 637  605                  sleep 5
 638  606             fi
↓ open down ↓ 8 lines elided ↑ open up ↑
 647  615  
 648  616          if ! echo ${onstat_header} | /usr/xpg4/bin/grep -q "shared memory not initialized"
 649  617          then
 650  618             /usr/cluster/bin/pmfadm -s ${RESOURCEGROUP},${RESOURCE},0.svc KILL 2> /dev/null
 651  619          fi
 652  620  
 653  621          debug_message "Function: stop_ids - End"
 654  622          return 0
 655  623  }
 656  624  
 657      -smf_wait_for_online()
 658      -{
 659      -        debug_message "Function: smf_wait_for_online - Begin"
 660      -        ${SET_DEBUG}
 661      -
 662      -        # In order to ensure that the SMF service is really online, we need
 663      -        # to check getstate() and check_ids(). However, we need to enforce
 664      -        # an SMF_EXIT_ERR_CONFIG if we are just about to timeout. If we do not
 665      -        # do this, then svc.startd will try to restart the SMF service three
 666      -        # times. Essentially we need Sun Cluster to do that.
 667      -
 668      -        MAX_START_TIMEOUT=`/usr/bin/expr ${START_TIMEOUT} \* 95 \/ 100`
 669      -        SECONDS=0
 670      -
 671      -        while  [ "${SECONDS}" -lt "${MAX_START_TIMEOUT}" ]
 672      -        do
 673      -           get_state
 674      -           check_ids
 675      -           rc=$?
 676      -
 677      -           # Check_ids will return 0 if
 678      -           # - The Informix Server is running
 679      -           # - No blocked on "MEDIA FAILURE" or "HANG_SYSTEM" exists
 680      -
 681      -           if [ "${rc}" -eq 0 ]
 682      -           then
 683      -                SECONDS=${MAX_START_TIMEOUT}
 684      -           else
 685      -                rc=${SMF_EXIT_ERR_CONFIG}
 686      -                sleep 2
 687      -           fi
 688      -        done
 689      -
 690      -        debug_message "Function: smf_wait_for_online - End"
 691      -        return ${rc}
 692      -}
 693      -
 694  625  cleanup_ipc()
 695  626  {
 696  627          debug_message "Function: cleanup_ipc - Begin"
 697  628          ${SET_DEBUG}
 698  629  
 699  630          # Cleanup any IPC shared memory segments however only if
 700  631          #
 701  632          #       - The shared memory segment(s) are owned by
 702  633          #               OWNER=root and GROUP=informix
 703  634          #       - The shared memory has no attached processes
↓ open down ↓ 14 lines elided ↑ open up ↑
 718  649             while read SHMID CPID LPID
 719  650             do
 720  651                  if /usr/bin/ps -p ${LPID} -o zone | /usr/bin/grep " ${ZONENAME}$" > /dev/null
 721  652                  then
 722  653                     debug_message "Informix SHMID: ${SHMID} - LPID ${LPID} is running"
 723  654                  else
 724  655                     if /usr/bin/ps -p ${CPID} -o zone | /usr/bin/grep " ${ZONENAME}$" > /dev/null
 725  656                     then
 726  657                          debug_message "Informix SHMID: ${SHMID} - CPID ${CPID} is running"
 727  658                     else
 728      -                        SHMID=`/usr/bin/echo ${SHMID} | /usr/xpg4/bin/tr 'm' ' '`
      659 +                        SHMID=$(/usr/bin/echo ${SHMID} | /usr/xpg4/bin/tr 'm' ' ')
 729  660  
 730  661                          # As the initial ipcs -mcopbZ is only a snapshot in time, Informix
 731  662                          # may have already cleaned up. Therefore the following attempt to remove a 
 732  663                          # shared memory segment may fail with "not found". To prevent misleading 
 733  664                          # console messages stdout/stderr is redirected to /dev/null. 
 734  665  
 735  666                          /usr/bin/ipcrm -z ${ZONENAME} -m ${SHMID} > /dev/null 2>&1
 736  667  
 737  668                          debug_message "Informix SHMID: ${SHMID} - removed"
 738  669  
↓ open down ↓ 28 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX