Sun Cluster Geographic Edition System Administration Guide

Chapter 14 Customizing Switchover and Takeover Actions

This chapter describes how you can create a script that is executed when a protection group's role changes from secondary to primary. The chapter contains the following topics:

Creating a Role-Change Action Script

You can configure the Sun Cluster Geographic Edition software to run a command when a cluster within a protection group changes from the secondary to the primary role. This change can happen as a result of either a switchover or takeover operation.

The action command is executed on the cluster where the role is changing from secondary to primary, with arguments that provide information about the event. The script is executed before the Sun Cluster Geographic Edition software bring the resource groups online. The following command-line runs the script:


# custom-action-command-path -o primary -c cluster-name \ 
 -s partnership-name protection-group-name user-arguments
custom-action-command-path

Specifies a path to the action command you have created.

-o primary

Specifies that the role being assumed by the cluster is primary.

-c cluster-name

Specifies the name of the secondary cluster that is assuming the new role of primary cluster.

-s partnership-name

Specifies the name of the partnership that hosts the protection group.

protection-group-name

Specifies the name of the protection group that is undergoing the role change.

user-arguments

Specifies static arguments that are passed after all of the Sun Cluster Geographic Edition supplied options.

This free-form string can be parsed by the script as required. For example, you could specify a list of key=value pairs, such as name=sun.com,ip=10.1.2.3. You could also specify a sequence of options, such as -n sun.com -a 10.1.2.3.4. The format of these arguments is not restricted by the Sun Cluster Geographic Edition software.

The exit status of the role-change action script is reported as part of the result of the geopg switchover or geopg takeover command. The exit status is zero if the action script was launched successfully. A nonzero exit status indicates an error or failure. The value of the exit status does not affect other aspects of the role-change actions. The switchover or takeover proceeds to bring the application resource groups in the protection group online, regardless of the exit status of the action script.

You should wait for the script to return before proceeding with other operation. Consider the time required to run the script when creating the action script.


Example 14–1 Switchover Action Script for Updating the DNS

This example creates a script that uses the nsupdate command to reconfigure the host name to point to a new cluster. For more information about the nsupdate command, refer to the nsupdate(1M) man page.

Clients that try to connect to companyX.com are referred by the name service to the address of the primary cluster for a protection group, cluster-paris. When the primary cluster fails to respond, the administrator performs a switchover of the protection group to the alternative cluster, cluster-newyork.


#!/bin/ksh
# script to update dns
# Assumes each cluster has an entry with name "lh-paris-1" in /etc/hosts
# but different value for the IP in each cluster
# for forward DNS (A) entry: will delete old entry for "lh-paris-1"
# and add one that is correct for "this cluster"
#
# For reverse (PTR) DNS entry, will just add one for this cluster. 
# Will NOT delete PTR record left over from old cluster. So
# eventually you will just have reverse lookup for the IP for both clusters
# doing reverse resolution to the same name (lh-paris-1.odyssey.com)
# This should be fine, as long as the forward resolution stays "correct"
#
# The blank line of input at the end of nsupdate is REQUIRED
#
# A short TTL is put on the new records (600 = 10 minutes)
# but you can't really control what kind of caching goes on on
# the client side


# get IP corresponding to name "lh-paris-1" on THIS Cluster
NEWIP=$(getent hosts lh-paris-1|cut -f1)

# this bit splits out the octets in order to add the reverse PTR entry
IFS=.
set $NEWIP
unset IFS

/usr/sbin/nsupdate <<ENDNSUPDATE
update delete ora-lh.odyssey.com A
update add ora-lh.odyssey.com 600 A $NEWIP
update add $4.$3.$2.$1.in-addr.arpa 600 PTR ora-lh.odyssey.com.

ENDNSUPDATE

Configuring a Protection Group to Execute a Script at Switchover or Takeover

After you have created a script, you must configure the protection group to execute the script if a switchover or takeover occurs. If a switchover or takeover occurs, the script is executed on the cluster that is becoming primary.

ProcedureHow to Configure a Protection Group to Execute a Script at Switchover or Takeover

Steps
  1. Log in to one of the cluster nodes.

    You must be assigned the Geo Management RBAC rights profile to complete this procedure. For more information about RBAC, see Sun Cluster Geographic Edition Software and RBAC.

  2. Configure the RoleChange_ActionCmd and RoleChange_ActionArgs properties of the protection group.


    # geopg set-prop -p RoleChange_ActionCmd=fully-qualified-script -p RoleChange_ActionArgs=script-arguments
    
    -p property-setting

    Sets the properties of the protection group

    Specify the path to the command by using the RoleChange_ActionCmd property. This path should be valid on all nodes of all partner clusters that can host the protection group.

    Define the arguments that you want to append to the command line when the action command is run by using the RoleChange_ActionArgs property.

    For more information about the properties you can set, see Appendix A, Standard Sun Cluster Geographic Edition Properties.

    protection-group-name

    Specifies the name of the protection group


Example 14–2 Configuring a Protection Group to Execute a Command at Cluster Switchover or Takeover

The following command configures a protection group to execute a custom command called newDNS:


# geopg set-prop -p RoleChange_ActionCmd=/usr/bin/newDNS \
-p RoleChange_ActionArgs=domain=companyx.com,ip=1.2.3.4 avspg