Sample customized clinfo.rc script

The sample Clinfo client application program, cl_status, is shown here within the context of a typical customized clinfo.rc script. clinfo.rc is the PowerHA® SystemMirror® for AIX® script run by Clinfo following cluster topology changes. The script and the program are commented to explain their usage.

#!/bin/ksh
##############################################################################
# Filename: /usr/sbin/cluster/etc/clinfo.rc
#
# Description: clinfo.rc is run by clinfo on clients following cluster
#     topology changes. This particular example demonstrates
#     user process management for a highly available database in a
#     two-node primary/standby configuration. Most database
#     client programs are state-dependent, and require 
      #restart following a node failure. This example provides 
#     user notification and application shutdown during 
#     appropriate topology changes.
#
#############################################################################
##############################################################################
# Grab Parameters Passed
##############################################################################
EVENT=$1 # action, one of {join, fail, swap}
INTERFACE=$2 # target address label
CLUSTERNAME="cluster1" # cluster name
NODENAME="victor"# primary node name
WATCHIF="svc_en0"# interface to monitor

##############################################################################
#   Name:  _arp_flush
#   This function flushes the entire arp cache.
#   Arguments:  none
#   Return value:  none
##############################################################################
_arp_flush()
{
  for IPADDR in $(/etc/arp -a |/bin/sed -e 's/^.*(.*).*$//' -e /incomplete/d)
    do
 /etc/arp -d $IPADDR
    done
}

##############################################################################
#
#   Name:  _kill_user_procs
#
#   This function kills user processes associated with the specified 
#   interface.
#
#   Arguments:  interface
#   Return value:  none
##############################################################################
_kill_user_procs()
{
    print _kill_user_procs
  # place commands appropriate to the database in use here

}
# The main if statement disregards status changes for all interfaces except
# WATCHIF, which in this example is svc_en0.
if [[ "$INTERFACE" = "WATCHIF" ]]  
then
  case "$EVENT" in
    "join") # interface label $INTERFACE has joined the cluster
# perform necessary activity here, such as user notification, restoration of
# user access, and arp cache flushing.
    exit 0
    ;;

    "fail")# Use api calls in cl_status to determine if interface 
    # failure is a result of node failure. 

  CLSTAT_MSG=$(cl_status $CLUSTERNAME $NODENAME)
  CLSTAT_RETURN=$?  # return code from cl_status
 
  case "$CLSTAT_RETURN" in
    0)      # Node UP
 # Notify users of application availability
      wall "Primary database is now available."      
  # flush arp cache
      _arp_flush
;; 

    1)      # Node DOWN
      # Notify users of topology change and restart requirement
      touch /etc/nologin    # prevent new logins
      wall "Primary database node failure. Please login again 
  2 minutes"
  sleep 10
      # Kill all processes attached to WATCHIF interface
      _kill_user_procs $WATCHIF
      # flush arp cache
_ arp_flush
  rm -f /etc/nologin     # enable logins
  ;;
  
    *)  # Indeterminate node state
 # flush arp cache
      _arp_flush
exit 1
;;

  esac  # case $CLSTAT_RETURN
  ;;
    "swap")# interface has been swapped
    # flush arp cache.
      _arp_flush
    ;;

  esac      # case $EVENT
else
    # event handling for other interfaces here, if desired
    /bin/true
fi