Oracle Solaris Cluster Generic Data Service (GDS) Guide

Exit Print View

Updated: July 2014, E48652-01
 
 

ORCL.gds Demo Scripts

The following demo scripts have been provided for a resource of type ORCL.gds:

  • /opt/ORCLscgds/demo/demo_probe

  • /opt/ORCLscgds/demo/demo_start

  • /opt/ORCLscgds/demo/demo_stop

  • /opt/ORCLscgds/demo/demo_validate


Note -  Within these demo scripts, the host name or interposed host name is output as a debug message to the system log. The purpose of this is to show that if the Interpose_logical_hostname extension property has been set, then the exported SC_LHOSTNAME variable value is returned as the interposed host name.

In the Oracle Solaris Cluster environment, an application might attempt to access the same host name after a failover or switchover. As a result, the failover or switchover fails because the name of the physical host changes after the failover or switchover. In such a scenario, the application data service can use the Interpose_logical_hostname to provide a logical host name to the application rather than a physical host name.

Demo_start Script

The demo_start script starts an application, which is a background sleep for 1800 seconds. Additionally, it prints out debug messages to the system log to show Begin and End messages and the hostname or interposed hostname.

01 #
02 # Copyright (c)2013, 2014, Oracle and/or its affiliates. All rights reserved.
03 #
04 #ident "@(#)demo_start.ksh 1.2     14/02/10"
05 #
06 
07 . /opt/ORCLscgds/lib/gds_functions
08 get_opts "$@"
09 
10 debug_message "Script: demo_start - Begin"
11 ${DEBUG}
12 trap 'debug_message "Script: demo_start - End (${rc})"' EXIT
13 trap 'errtrap "Script: demo_start" ${LINENO}; rc=1; exit 1' ERR
14
15 typeset -i rc=0
16 typeset ilh
17 typeset pmf
18
19 ilh=$(/usr/cluster/bin/scha_resource_get -O extension \
20     -R ${RESOURCE} -G ${RESOURCEGROUP} interpose_logical_hostname)
21 
22 ilh=$(echo ${ilh} | /usr/xpg4/bin/awk '{print$2}')
23 
24 pmf=$(/usr/cluster/bin/scha_resource_get -O extension \
25     -R ${RESOURCE}  -G ${RESOURCEGROUP} pmf_managed)
26 
27 pmf=$(echo ${pmf} | /usr/xpg4/bin/awk '{print$2}')
28 
29 if (( ${#ilh} != 0 )); then
30     if [[ ${pmf} != TRUE ]]; then
31          interpose_logical_hostname ${RESOURCE} ${RESOURCEGROUP}
32     fi
33 fi
34 
35 debug_message "Script: demo_start - hostname is $(/usr/bin/hostname)"
36
37 /usr/bin/sleep 1800 &
38
39 if [[ -f ${DEBUG_LOGFILE} ]]; then
40     /usr/bin/printf "--- $(date) - rc=${rc} \n" >> ${DEBUG_LOGFILE}
41     /usr/bin/printf "Script: demo_start - hostname is $(/usr/bin/hostname) \n" >> ${DEBUG_LOGFILE}
42 fi
43 
44 exit ${rc}
  • Lines 07-09 – The function get_opts processes all the arguments that GDSv2 passes to demo_start. Those arguments are processed as upper case KSH variables. Property values are as defined. For example, RESOURCE=myrs.

  • Lines 10-11 – The function debug_message is called to output a Begin debug message to the system log. Additionally, the ${DEBUG} variable is set. See Debug_level Property for more information.

  • Lines 12-13 – The KSH trap built-in command is used to output an End debug message to the system log whenever the script exists. Additionally, if a command returns a non-zero exit status the KSH fake signal ERR is trapped and the function errtrap is called. Function errtrap will output an error message to the system log that contains the script name, line number of the command that returned a non-zero exit status, and the exit status that was returned by that command.

  • Lines 19-22 – The Oracle Solaris Cluster program scha_resource_get retrieves the interpose_logical_hostname extension property, which is saved into the variable ilh.

  • Lines 24-27 – The Oracle Solaris Cluster program scha_resource_get retrieves the pmf_managed extension property which is saved into the variable pmf.

  • Lines 29-33 – If the interpose_logical_hostname extension property was set and the pmf_managed extension property was not set to TRUE, then the function interpose_logical_hostname is called. However, if interpose_logical_hostname was set and pmf_managed was set to TRUE, then environment variables for SC_LHOSTNAME are defined. See Interpose_logical_hostname Property for more information.

    If the function interpose_logical_hostname is called, then environment variables for SC_LHOSTNAME are defined.

  • Line 35 – Output a debug message to the system log that contains the script name and value from the hostname command. If environment variables for SC_LHOSTNAME exist, then the value for SC_LHOSTNAME is output.

  • Line 37 – Start the application. For example, sleep 1800 in the background.

  • Lines 39-42 – If variable ${DEBUG_LOGFILE} is set, then output some debug_messages to that file. When function debug_messages was first called on line 10, ${DEBUG_LOGFILE} was set to /var/cluster/logs/DS/RT/message_log.RS.. RT equals ORCL.gds and RS equals your resource name.

Demo_probe Script

The demo_probe script checks if the application is running (for example, the background sleep for 1800 seconds). Additionally, it prints out debug messages to the system log to show Begin and End messages and the hostname or interposed hostname.

01 #
02 # Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
03 #
04 #ident  "@(#)demo_probe.ksh 1.2     14/02/10"
05 #
06 
07 . /opt/ORCLscgds/lib/gds_functions
08 get_opts "$@"
09 
10 eval typeset -r method=\$$#
11 debug_message "Script: demo_probe - Begin"
12 ${DEBUG}
13 trap 'debug_message "Script: demo_probe - End (${rc})"' EXIT
14 trap 'errtrap "Script: demo_probe" ${LINENO}; rc=1; exit 1' ERR
15 
16 typeset -i rc=0
17 typeset ilh
18 typeset pmf
19 
20 ilh=$(/usr/cluster/bin/scha_resource_get -O extension \
21     -R ${RESOURCE} -G ${RESOURCEGROUP} interpose_logical_hostname)
22 
23 ilh=$(echo ${ilh} | /usr/xpg4/bin/awk '{print$2}')
24 
25 pmf=$(/usr/cluster/bin/scha_resource_get -O extension \
26     -R ${RESOURCE} -G ${RESOURCEGROUP} pmf_managed)
27 
28 pmf=$(echo ${pmf} | /usr/xpg4/bin/awk '{print$2}')
29 
30 if (( ${#ilh} != 0 )); then
31     if [[ ${pmf} != TRUE ]]; then
32         interpose_logical_hostname ${RESOURCE} ${RESOURCEGROUP}
33     fi
34 fi
35 
36 debug_message "Script: demo_probe - hostname is $(/usr/bin/hostname)"
37 
38 if /usr/bin/ps -u root -o pid,args -z $(/usr/bin/zonename) | /usr/xpg4/bin/grep -q "sleep
     1800"; then
39     # Return code 0 declares a success.
40     rc=0
41 else 
42     # Return code 100 declares a complete failure.
43   rc=100
44 fi
45 
46 if [[ -f ${DEBUG_LOGFILE} ]]; then
47     /usr/bin/printf "--- $(date) - rc=${rc} \n" >> ${DEBUG_LOGFILE}
48     /usr/bin/printf "Script: demo_probe - method name is ${method} \n" >> ${DEBUG_LOGFILE}
49     /usr/bin/printf "Script: demo_probe - hostname is $(/usr/bin/hostname) \n" >>
            ${DEBUG_LOGFILE}
50 fi
51 
52 exit ${rc}
  • Lines 07-36 – Apart from line 10, these lines are explained with the demo_start script.

  • Line 10 – The last argument that GDSv2 passes to the demo_probe script is saved in the method variable.


    Note -  The last argument, 'gds_start | gds_probe', is provided so that you can code different behavior within the Probe_command.
  • Lines 38-44 – A check is made to see if the application (for example, sleep 1800) is still running. If the sleep is still running, then the demo_probe script will exit 0. Otherwise, exit 100 will be sent to GDSv2 to declare a complete failure.

    The RGM responds to a complete failure by checking the Failover_mode property to determine what recovery action to take. See Probe_command Property and the r_properties (5) man page for more information.

  • Lines 46-47 – These lines are explained with the demo_start script.

Demo_stop Script

The demo_stop script stops the application (for example, the background sleep for 1800 seconds). Additionally, it prints out debug messages to the system log to show Begin and End messages and the hostname or interposed host name.

01 #
02 # Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
03 #
04 #ident  "@(#)demo_stop.ksh 1.2     14/02/10"
05 #
06 
07 . /opt/ORCLscgds/lib/gds_functions
08 get_opts "$@"
09 
10 debug_message "Script: demo_stop - Begin"
11 ${DEBUG} 
12 trap 'debug_message "Script: demo_stop - End (${rc})"' EXIT
13 trap 'errtrap "Script: demo_stop" ${LINENO}; rc=1; exit 1' ERR
14 
15 typeset -i rc=0
16 typeset ilh
17 typeset pmf
18 
19 ilh=$(/usr/cluster/bin/scha_resource_get -O extension \
20     -R ${RESOURCE} -G ${RESOURCEGROUP} interpose_logical_hostname)
21 
22 ilh=$(echo ${ilh} | /usr/xpg4/bin/awk '{print$2}')
23 
24 pmf=$(/usr/cluster/bin/scha_resource_get -O extension \
25     -R ${RESOURCE} -G ${RESOURCEGROUP} pmf_managed)
26 
27 pmf=$(echo ${pmf} | /usr/xpg4/bin/awk '{print$2}')
28 
29 if (( ${#ilh} != 0 )); then
30     if [[ ${pmf} != TRUE ]]; then
31         interpose_logical_hostname ${RESOURCE} ${RESOURCEGROUP}
32     fi
33 fi
34 
35 debug_message "Script: demo_stop - hostname is $(/usr/bin/hostname)"
36 
37 pid=$(/usr/bin/ps -u root -o pid,args -z $(/usr/bin/zonename) | \
38     /usr/xpg4/bin/grep "sleep 1800" | /usr/xpg4/bin/grep -v grep | \
39     /usr/xpg4/bin/awk '{print $1}')
40 
41 if (( ${#pid} != 0 )); then
42     /usr/bin/kill -9 ${pid}
43 fi
44 
45 if [[ -f ${DEBUG_LOGFILE} ]]; then
46     /usr/bin/printf "--- $(date) - rc=${rc} \n" >> ${DEBUG_LOGFILE}
47     /usr/bin/printf "Script: demo_stop - hostname is $(/usr/bin/hostname) \n" >> ${DEBUG_LOGFILE}
48 fi
49 
50 exit ${rc}
  • Lines 07-35 – These lines are explained with the demo_start script.

  • Lines 37-42 – Find the process ID for the application started by the demo_start script (for example, 'sleep 1800') and then kill that process ID.

  • Lines 45-49 – These lines are explained with the demo_start script.

Demo_validate Script

The demo_validate script validates extension properties used by a resource of type ORCL.gds. The function get_opts provides upper case KSH global variables. Property values are as defined (for example, RESOURCE=myrs). Additionally, the function get_opts will set the HASP KSH global variable (for example, HASP=SCDS_HASP_NO_RESOURCE). See Validate_command Property for more information.

01 #
02 # Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
03 #
04 #ident  "@(#)demo_validate.ksh 1.2     14/02/10" 
05 #
06 
07 . /opt/ORCLscgds/lib/gds_functions
08 get_opts "$@"
09 
10 debug_message "Script: demo_validate - Begin"
11 trap 'debug_message "Script: demo_validate - End (${rc})"' EXIT
12 trap 'errtrap "Script: demo_validate" ${LINENO}; rc=1; exit 1' ERR
13 typeset -i rc=0
14 
15 exit ${rc}
  • Lines 07-15 – These lines are explained with the demo_start script.