2.4. Script Format

Templates for the action scripts are provided in the following directory:

/usr/lib/failsafe/resource_types/template

The template scripts have the same general format. Following is the order in which the information appears in the script:

The following sections show an example from the NFS start script. Note that the contents of these examples may not match the latest software.

2.4.1. Header Information

The header information contains comments about the resource type, script type, and resource configuration format. You must modify the code as needed.

Following is the header for the NFS start script:

#!/bin/sh
 
# **************************************************************************
# *                                                                        *
# *                  Copyright (C) 1998 Silicon Graphics, Inc.             *
# *                                                                        *
# *  These coded instructions, statements, and computer programs  contain  *
# *  unpublished  proprietary  information of Silicon Graphics, Inc., and  *
# *  are protected by Federal copyright law.  They  may  not be disclosed  *
# *  to  third  parties  or copied or duplicated in any form, in whole or  *
# *  in part, without the prior written consent of Silicon Graphics, Inc.  *
# *                                                                        *
# **************************************************************************

#ident "$Revision: 1.2 $"

# Resource type: NFS
# Start script NFS
 
#
# Test resource configuration information is present in the database in
# the following format
#
# resource-type.NFS

2.4.2. Set Local Variables

The set_local_variables() section of the script defines all of the variables that are local to the script, such as temporary file names or database keys. All local variables should use the LOCAL_ prefix. You must modify the code as needed.

Following is the set_local_variables() section from the NFS start script:

set_local_variables()
{
    LOCAL_TEST_KEY=NFS
}

2.4.3. Read Resource Information

The  get_xxx_info() function, such as get_nfs_info(), reads the resource information from the cluster configuration database. $1 is the test resource name. If the operation is successful, a value of 0 is returned; if the operation fails, 1 is returned.

The information is returned in the HA_STRING variable. For more information about HA_STRING, see Appendix B.

Following is the get_nfs_info() section from the NFS start script

get_nfs_info ()
{
    ha_get_info ${LOCAL_TEST_KEY} $1
    if [ $? -ne 0 ]; then
        return 1;
    else
        return 0;
    fi
}

If you wish to get resource dependency information, you can call ha_get_info with a third argument of any value. The resource dependency list will be returned in the HA_STRING variable.

2.4.4. Exit Status

In the exit_script() function, $1 contains the exit_status value. If cleanup actions are required, such as the removal of temporary files that were created as part of the process, place them before the exit line.

Following is the exit_script() section from the NFS start script

exit_script()
{
    exit $1;
}

Note: If you call the exit_script function prior to normal termination, it should be preceded by the ha_write_status_for_resource function and you should use the same return code that is logged to the output file. For more information see Appendix B.

2.4.5. Basic Action

This area of the script is the portion you must customize. The templates provide a minimal framework.

Following is the framework for the basic action from the start template:

start_template()

# for all template resources passed as parameter
for TEMPLATE in $HA_RES_NAMES
do
    #HA_CMD="command to start $TEMPLATE resource on the local machine";

    #ha_execute_cmd "string to describe the command being executed";

    ha_write_status_for_resource $TEMPLATE $HA_SUCCESS;
done
}

Note: When testing the script, you can obtain debugging information by adding the shell command set -x to this section.

For examples of this area, see Section 2.6.

2.4.6. Set Global Variables

The following lines set all of the global and local variables and store the resource names in $HA_RES_NAMES.

Following is the set_global_variables() function from the NFS start script:

set_global_variables()
{
    HA_DIR=/usr/lib/failsafe
    COMMON_LIB=${HA_DIR}/common_scripts/scriptlib
 
    # Execute the common library file
    . $COMMON_LIB
 
    ha_set_global_defs;
}

2.4.7. Verify Arguments

The ha_check_args() function verifies the arguments and stores them in the $HA_INFILE and $HA_OUTFILE variables. It returns 1 on error and 0 on success.

Following is the following is the section from the NFS start script that calls ha_check_args:

ha_check_args $*;
if [ $? -ne 0 ]; then
    exit $HA_INVAL_ARGS;
fi

2.4.8. Read Input File

The ha_read_infile() function reads the input file and stores the resource names in the $HA_RES_NAMES variable.

Following is the ha_read_infile() function from the common library file scriptlib:

ha_read_infile()
{
    HA_RES_NAMES="";
 
    for HA_RESOURCE in `cat ${HA_INFILE}`
    do
        HA_TMP="${HA_RES_NAMES} ${HA_RESOURCE}";
        HA_RES_NAMES=${HA_TMP};
    done
}

2.4.9. Complete the Action

Located at the bottom of the script file are the lines which perform the actual work of the requested action using the prior sections and provided tools. The results are written as output to $HA_OUTFILE:

action_resourcetype;
 
exit_script $HA_SUCCESS

Following is the completion from the NFS start script:

start_nfs;
 
exit_script $HA_SUCCESS;