Go to main content

Oracle® Solaris Cluster Generic Data Service (GDS) Guide

Exit Print View

Updated: September 2015
 
 

Using the GDSv2 Demo Scripts

This section contains information about the demo scripts that are provided with GDSv2. These demo scripts can be used with a resource of type ORCL.gds or ORCL.gds_proxy to start, stop, and monitor or proxy the demo applications.

The benefit of a demo application is to quickly deploy a GDSv2 resource with minimal effort. You can then experiment with the various GDSv2 extension properties to learn about the functionality.


Note -  GDSv2 demo scripts are located in the /opt/ORCLscgds/demo directory and use the Korn Shell (KSH). All functions listed below are located within the /opt/ORCLscgds/lib directory.

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.

ORCL.gds_proxy Demo Scripts

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

  • /opt/ORCLscgds/demo/demo_proxy_prenet_start

  • /opt/ORCLscgds/demo/demo_proxy_postnet_stop

  • /opt/ORCLscgds/demo/demo_validate


Note -  The RGM will execute the demo_proxy_prenet_start script before any logical host network interfaces are configured up and execute demo_proxy_postnet_stop after any logical host network interface are configured down. Nevertheless, it is still possible to set the interpose_logical_hostname property, which will return the exported SC_LHOSTNAME variable value as the interposed host name even though that host name may not be configured up.

Demo_proxy_prenet_start Script

The demo_proxy_prenet_start script is executed as a daemon and checks the state of the system log. 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_proxy_prenet_start.ksh 1.2     14/02/10"
05 #
06 
07 . /opt/ORCLscgds/lib/gds_functions
08 get_opts "$@"
09 
10 debug_message "Script: demo_prenet_start_proxy - Begin"
11 ${DEBUG}
12 trap 'debug_message "Script: demo_prenet_start_proxy - End (${rc})"' EXIT
13 trap 'errtrap "Script: demo_prenet_start_proxy" ${LINENO}; rc=1; exit 1' ERR
14 
15 typeset -i rc=0
16 typeset -r scha_control=/usr/cluster/bin/scha_control
17 typeset -r set_status=/usr/cluster/bin/scha_resource_setstatus
18 typeset -r rs_get=/usr/cluster/bin/scha_resource_get
19 typeset status
20 typeset interval
21 
22 debug_message "Script: demo_prenet_start_proxy - hostname is $(/usr/bin/hostname)"
23 
24 if [[ -f ${DEBUG_LOGFILE} ]]; then
25     /usr/bin/printf "--- $(date) - rc=${rc} \n" >> ${DEBUG_LOGFILE}
26     printf "Script: demo_prenet_start_proxy - hostname is $(/usr/bin/hostname) \n" >>
            ${DEBUG_LOGFILE}
27 fi
28 
29 interval=$(/usr/cluster/bin/scha_resource_get -O extension -R ${RESOURCE} -G ${RESOURCEGROUP}
     proxy_interval)
30 interval=$(echo ${interval} | /usr/xpg4/bin/awk '{print $2}')
31 
32 while :
33 do
34     status=$(/usr/bin/svcs -Ho state system-log)
35 
36     case ${status} in
37         disabled)   ${scha_control} -O CHANGE_STATE_OFFLINE -R ${RESOURCE} -G ${RESOURCEGROUP}
38                ${set_status} -R ${RESOURCE} -G ${RESOURCEGROUP} -s OFFLINE -m "System-log is
                       offline"
39                ;;
40       online   ${scha_control} -O CHANGE_STATE_ONLINE -R ${RESOURCE} -G ${RESOURCEGROUP}
41                ${set_status} -R ${RESOURCE} -G ${RESOURCEGROUP} -s OK -m "System-log is online"
42                ;;
43       *)       ${scha_control} -O CHANGE_STATE_OFFLINE -R ${RESOURCE} -G ${RESOURCEGROUP}
44                ${set_status} -R ${RESOURCE} -G ${RESOURCEGROUP} -s DEGRADED -m "System-log is
                       degraded"
45                ;;
46     esac
47 
48     sleep ${interval}
49 done
50 
51 exit ${rc}
  • Lines 07-09 – The function get_opts will process all the arguments that GDSv2 passes to demo_proxy_prenet_start. Those arguments are processed as upper case KSH variables. Property values are as defined (for example, RESOURCE=mysrs).

  • 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 – 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 exist status and the exit status that was returned by that command.

  • Line 22 – 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.

  • Lines 24-27 – 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_proxy and RS equals your resource name.

  • Lines 29-30 – The Oracle Solaris Cluster program scha_resource_get retrieves the proxy_interval extension property, which is saved into the variable interval.

  • Lines 32-49 – Perform a while loop sleeping for the duration of ${interval} on every iteration. During each iteration, check the state of the system log using the svcs(1) command and reflect that state as an Oracle Solaris Cluster resource state and status.

Demo_proxy_postnet_stop Script

The demo_proxy_postnet_stop script is executed when the daemon that was started by demo_proxy_prenet_start is being stopped. 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_proxy_postnet_stop.ksh 1.3     14/02/10"
05 #
06 
07 . /opt/ORCLscgds/lib/gds_functions
08 get_opts "$@"
09
10 debug_message "Script: demo_postnet_stop_proxy - Begin"
11 ${DEBUG}
12 trap 'debug_message "Script: demo_postnet_stop_proxy - End (${rc})"' EXIT
13 trap 'errtrap "Script: demo_proxy_postnet_stop" ${LINENO}; rc=1; exit 1' ERR
14 
15 typeset -i rc=0
16 typeset -r set_status=/usr/cluster/bin/scha_resource_setstatus
17 
18 debug_message "Script: demo_postnet_stop_proxy - hostname is $(/usr/bin/hostname)"
19 
20 ${set_status} -R ${RESOURCE} -G ${RESOURCEGROUP} -s OFFLINE
21 
22 if [[ -f ${DEBUG_LOGFILE} ]]; then
23     /usr/bin/printf "--- $(date) - rc=${rc} \n" >> ${DEBUG_LOGFILE}
24     /usr/bin/printf "Script: demo_postnet_stop_proxy - hostname is $(/usr/bin/hostname) \n" >>
            ${DEBUG_LOGFILE}
25 fi
26 
27 exit ${rc}
  • Lines 07-27 – All these lines are explained with the demo_proxy_prenet_start script.