Print this page
Split Close
Expand all
Collapse all
          --- /workspace/du105637/oscposthot/webrev/usr/src/cmd/ha-services/gds-agents/PostgreSQL/functions_static.ksh-
          +++ functions_static.ksh
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14  # When distributing Covered Code, include this CDDL HEADER in each
  15   15  # file and include the License file at usr/src/CDDL.txt.
  16   16  # If applicable, add the following below this CDDL HEADER, with the
  17   17  # fields enclosed by brackets [] replaced with your own identifying
  18   18  # information: Portions Copyright [yyyy] [name of copyright owner]
  19   19  #
  20   20  # CDDL HEADER END
  21   21  #
  22   22  
  23   23  #
  24      -# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
       24 +# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  25   25  # Use is subject to license terms.
  26   26  #
  27   27  
  28   28  #ident  "%Z%%M% %I%     %E% SMI"
  29   29  
  30   30  TASK_COMMAND=""
  31   31  
  32   32  ZONENAME=/usr/bin/zonename
  33   33  
  34   34  SCLOGGER=/usr/cluster/lib/sc/scds_syslog
  35   35  LOGGER=/usr/bin/logger
  36   36  SCHA_RESOURCE_SETSTATUS=/usr/cluster/bin/scha_resource_setstatus
  37   37  SCHA_RESOURCE_GET=/usr/cluster/bin/scha_resource_get
  38   38  SCHA_RESOURCEGROUP_GET=/usr/cluster/bin/scha_resourcegroup_get
  39   39  PMFADM=/usr/cluster/bin/pmfadm
  40   40  UNAME=/usr/bin/uname
  41   41  ECHO=/usr/bin/echo
  42   42  AWK=/usr/bin/awk
  43   43  EGREP=/usr/bin/egrep
       44 +GREP=/usr/bin/grep
  44   45  PROJECTS=/usr/bin/projects
       46 +WC=/usr/bin/wc
       47 +CAT=/usr/bin/cat
       48 +ENV=/usr/bin/env
       49 +RM=/usr/bin/rm
       50 +SSH_AGENT=/usr/bin/ssh-agent
       51 +SSH_ADD=/usr/bin/ssh-add
       52 +CHMOD=/usr/bin/chmod
  45   53  
  46   54  terminate()
  47   55  {
  48   56  
  49   57          debug_message "Function: terminate - Begin"
  50   58          ${SET_DEBUG}
  51   59  
  52   60          exiting_func=${1}
  53   61          exit_code=${2}
  54   62  
↓ open down ↓ 82 lines elided ↑ open up ↑
 137  145  rgs_zonename()
 138  146  {
 139  147  
 140  148  # Determine wether the host specified by uname -n is combined with a zonename in the 
 141  149  # current resourcegroups nodelist. The seperator beween nodename and zonename is ":".
 142  150  #
 143  151  # This function assume the resource group name preset in the variable ${RESOURCEGROUP} and should be called 
 144  152  #
 145  153  # $(rgs_zonename) 
 146  154  #
 147      -# It passes back the zonename or nothing. 
      155 +# It passes back a zonename or nothing. 
      156 +# If there are more than one zones in the nodelist, it passes back either the zone where the resource group
      157 +# is online or first one in the list.
 148  158  
 149  159          debug_message "Function: rg_zonename - Begin "
 150  160          ${SET_DEBUG}
 151  161  
 152  162          nodes_zone=
 153  163          nodename=`${UNAME} -n`
 154      -        node=`${SCHA_RESOURCEGROUP_GET} -G ${RESOURCEGROUP} -O NODELIST|grep ${nodename}`
      164 +        node=`${SCHA_RESOURCEGROUP_GET} -G ${RESOURCEGROUP} -O NODELIST|${EGREP} "${nodename}$|${nodename}:"`
 155  165  
 156      -        if ${ECHO} ${node} | grep : >/dev/null 2>&1
      166 +        if ${ECHO} ${node} | ${GREP} : >/dev/null 2>&1
 157  167          then
 158      -                nodes_zone=`${ECHO} ${node} | ${AWK} -F: '{print $2}'`
      168 +                if [ `${ECHO} ${node}|${WC} -w` -gt 1 ]
      169 +                then
      170 +                        online=0
      171 +                        for i in ${node}
      172 +                        do
      173 +                                if ${SCHA_RESOURCEGROUP_GET} -G ${RESOURCEGROUP} -O RG_state_node ${i}| ${GREP} -i online >/dev/null 2>&1
      174 +                                then
      175 +                                        nodes_zone=`${ECHO} ${i} | ${AWK} -F: '{print $2}'`
      176 +                                        online=1
      177 +                                fi
      178 +                        done
      179 +
      180 +                        # check if we found a zone where the resource group is online, if not pick the first zone in the list
      181 +
      182 +                        if [ ${online} -eq 0 ]
      183 +                        then
      184 +                                first_node=`${ECHO} ${node} | ${AWK} '{print $1}'`
      185 +                                nodes_zone=`${ECHO} ${first_node} | ${AWK} -F: '{print $2}'`
      186 +                        fi
      187 +                else
      188 +                        nodes_zone=`${ECHO} ${node} | ${AWK} -F: '{print $2}'`
      189 +                fi
 159  190                  
 160  191          fi
 161  192  
 162  193          print ${nodes_zone}
 163  194  
 164  195          debug_message "Function: rg_zonename - End "
 165  196  }
 166  197  
 167  198  debug_message()
 168  199  {
↓ open down ↓ 313 lines elided ↑ open up ↑
 482  513             "${RESOURCE}" "${RESOURCE}"
 483  514  
 484  515             St=100
 485  516          else
 486  517             St=0
 487  518          fi
 488  519  
 489  520          debug_message "Function: restart_dependency - End"
 490  521  
 491  522          return ${St}
      523 +}
      524 +
      525 +start_ssh_agent()
      526 +{
      527 +        # 
      528 +        # Start an ssh-agent and add the decrypted private key.
      529 +        # Only when the ssh-agent contains the private key, a ssh login without a 
      530 +        # passphrase challenge is possible.
      531 +        #
      532 +        # This function stores the environment variables SSH_AUTH_SOCK and 
      533 +        # SSH_AGENT_PID in /tmp/${RESOURCE}-ssh in a ksh compatible format. 
      534 +        #
      535 +        # The start_ssh_agent function is meant to be called in the target users 
      536 +        # environment.
      537 +        #
      538 +        # The only necessary parameter is the passphrase of the target users
      539 +        # private ssh key.
      540 +        # If you use this function you should kill the started ssh-agent in your 
      541 +        # stop function.
      542 +        #
      543 +        # To do this you have to export the SSH_AGENT_PID from tmp/${RESOURCE}-ssh
      544 +        # in the users environment and call /usr/bin/ssh-agent -k.
      545 +        #
      546 +        # The returncode of the start_ssh_agent function is 0 for success, and 1 for error.
      547 +
      548 +        debug_message "Function: start_ssh_agent - Begin"
      549 +        ${SET_DEBUG}
      550 +
      551 +        SSH_PASS=${1}
      552 +
      553 +        rc_start_ssh_agent=0
      554 +        export DISPLAY=""
      555 +
      556 +        # remove the SSH_ASKPASS script and the temporary store of SSH_AUTH_SOCK 
      557 +        # and SSH_AGENT_PID to satisfy noclobber
      558 +
      559 +        ${RM} /tmp/${RESOURCE}-askpass 2>/dev/null
      560 +        ${RM} /tmp/${RESOURCE}-ssh 2>/dev/null
      561 +
      562 +        # start the ssh-agent
      563 +
      564 +        eval `${SSH_AGENT} -s` >/dev/null 2>&1
      565 +        if [ ${?} -eq 0 ]
      566 +        then
      567 +                debug_message "Function: start_ssh_agent - ssh-agent started"
      568 +
      569 +                ${ENV} | ${EGREP} "SSH_AUTH_SOCK|SSH_AGENT_PID">/tmp/${RESOURCE}-ssh
      570 +        
      571 +                # create the SSH_ASKPASS script needed for a headless ssh-agent
      572 +
      573 +                export SSH_ASKPASS=/tmp/${RESOURCE}-askpass
      574 +                ${CAT} > ${SSH_ASKPASS} <<EOF
      575 +#!/usr/bin/ksh
      576 +# reads a passphrase at the ssh-agent command
      577 +read x
      578 +${ECHO} \${x}
      579 +EOF
      580 +                ${CHMOD} +x ${SSH_ASKPASS}
      581 +
      582 +                # decrypt the private key and store it in memory
      583 +
      584 +                if  print ${SSH_PASS}|${SSH_ADD} >/dev/null 2>&1
      585 +                then
      586 +                        debug_message "Function: start_ssh_agent - ssh-add successful, private key decryped and stored"
      587 +                else
      588 +                        # SCMSGS
      589 +                        # @explanation
      590 +                        # The ssh passphrase passed to the start_ssh_agent function is wrong
      591 +                        # @user_action
      592 +                        # Fix the ssh passphrase entry in your parameters
      593 +                        scds_syslog -p daemon.err -t $(syslog_tag) -m \
      594 +                                "start_ssh_agent: The passphrase %s is wrong" \
      595 +                                "${SSH_PASS}" 
      596 +                        rc_start_ssh_agent=1
      597 +                fi
      598 +
      599 +                # remove the previously created askpass script
      600 +
      601 +                ${RM} ${SSH_ASKPASS}
      602 +        else
      603 +                # SCMSGS
      604 +                # @explanation
      605 +                # The ssh-agent is not startable for the given user
      606 +                # @user_action
      607 +                # Determine and fix the root cause by running the ssh-agent manually
      608 +                # as the target user
      609 +                scds_syslog -p daemon.err -t $(syslog_tag) -m \
      610 +                        "start_ssh_agent: The start of the ssh-agent was unsuccessful" 
      611 +                rc_start_ssh_agent=1
      612 +
      613 +        fi
      614 +
      615 +        debug_message "Function: start_ssh_agent - End"
      616 +        return ${rc_start_ssh_agent}
      617 +        
 492  618  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX