| Linux FailSafe™ Programmer's Guide | ||
|---|---|---|
| Prev | Chapter 2. Writing the Action Scripts and Adding Monitoring Agents | Next |
The following sections use portions of the NFS scripts as examples.
Note: The examples in this guide may not exactly match the released system.
The NFS start script does the following:
Creates a resource-specific NFS status directory.
Exports the specified export-point with the specified export-options.
Following is a section from the NFS start script:
# Start the resource on the local machine.
# Return HA_SUCCESS if the resource has been successfully started on the local
# machine and HA_CMD_FAILED otherwise.
#
start_nfs()
{
${HA_DBGLOG} "Entry: start_nfs()";
# for all nfs resources passed as parameter
for resource in ${HA_RES_NAMES}
do
NFSFILEDIR=${HA_SCRIPTTMPDIR}/${LOCAL_TEST_KEY}$resource
HA_CMD="mkdir -p $NFSFILEDIR";
ha_execute_cmd "creating nfs status file directory";
if [ $? -ne 0 ]; then
${HA_LOG} "Failed to create ${NFSFILEDIR} directory";
ha_write_status_for_resource ${resource} ${HA_NOCFGINFO};
exit_script $HA_NOCFGINFO
fi
get_nfs_info $resource
if [ $? -ne 0 ]; then
${HA_LOG} "NFS: $resource parameters not present in CDB";
ha_write_status_for_resource ${resource} ${HA_NOCFGINFO};
exit_script ${HA_NOCFGINFO};
fi
ha_get_field "${HA_STRING}" export-info
if [ $? -ne 0 ]; then
${HA_LOG} "NFS: export-info not present in CDB for resource $resource";
ha_write_status_for_resource ${resource} ${HA_NOCFGINFO};
exit_script ${HA_NOCFGINFO};
fi
export_opts="$HA_FIELD_VALUE"
ha_get_field "${HA_STRING}" filesystem
if [ $? -ne 0 ]; then
${HA_LOG} "NFS: filesystem-info not present in CDB for resource $resource";
ha_write_status_for_resource ${resource} ${HA_NOCFGINFO};
exit_script ${HA_NOCFGINFO};
fi
filesystem="$HA_FIELD_VALUE"
# Before we try and export the NFS resource, make sure
# filesystem is mounted.
HA_CMD="grep $filesystem /etc/mtab > /dev/null 2>&1";
ha_execute_cmd "check if the filesystem $filesystem is mounted";
if [ $? -ne 0 ]; then
${HA_LOG} "NFS: filesystem $filesystem not mounted";
ha_write_status_for_resource ${resource} ${HA_CMD_FAILED};
exit_script ${HA_CMD_FAILED};
fi
# Now do the job: export the new directory
# Note: the export_dir command will check wether this directory
# is already exported or not.
HA_CMD="export_dir ${resource} ${export_opts}";
ha_execute_cmd "export $resource directories to NFS clients";
if [ $? -ne 0 ]; then
${HA_LOG} "NFS: could not export resoure ${resource}"
ha_write_status_for_resource ${resource} ${HA_CMD_FAILED};
exit_script ${HA_CMD_FAILED};
else
ha_write_status_for_resource ${resource} ${HA_SUCCESS};
fi
done
} |
The NFS stop script does the following:
Unexports the specified export-point.
Removes the NFS status directory.
Following is an example from the NFS stop script:
# Stop the nfs resource on the local machine.
# Return HA_SUCCESS if the resource has been successfully stopped on the local
# machine and HA_CMD_FAILED otherwise.
#
stop_nfs()
{
${HA_DBGLOG} "Entry: stop_nfs()";
# for all nfs resources passed as parameter
for resource in ${HA_RES_NAMES}
do
get_nfs_info ${resource}
if [ $? -ne 0 ]; then
# NFS resource information not available.
${HA_LOG} "NFS: $resource parameters not present in CDB";
ha_write_status_for_resource ${resource} ${HA_NOCFGINFO};
exit_script ${HA_NOCFGINFO};
fi
ha_get_field "${HA_STRING}" export-info
if [ $? -ne 0 ]; then
${HA_LOG} "NFS: export-info not present in CDB for resource $resource";
ha_write_status_for_resource ${resource} ${HA_NOCFGINFO};
exit_script ${HA_NOCFGINFO};
fi
export_opts="$HA_FIELD_VALUE"
# Unexport the directory
HA_CMD="unexport_dir ${resource}"
ha_execute_cmd "unexport ${resource} directory to NFS clients"
if [ $? -ne 0 ]; then
${HA_LOG} "NFS: Failed to unexport resource ${resource}"
ha_write_status_for_resource ${resource} ${HA_CMD_FAILED}
fi
ha_write_status_for_resource ${resource} ${HA_SUCCESS}
done
} |
The NFS monitor script does the following:
Verifies that the file system is mounted at the correct mount point.
Requests the status of the exported file system.
Checks the export-point.
Requests NFS statistics and (based on the results) make a Remote Procedure Call (RPC) to NFS as needed.
Following is an example from the NFS monitor script:
# Check if the nfs resource is allocated in the local node
# This check must be light weight and less intrusive compared to
# exclusive check. This check is done when the resource has been
# allocated in the local node.
# Return HA_SUCCESS if the resource is running in the local node
# and HA_CMD_FAILED if the resource is not running in the local node
# The list of the resources passed as input is in variable
# $HA_RES_NAMES
#
monitor_nfs()
{
${HA_DBGLOG} "Entry: monitor_nfs()";
for resource in ${HA_RES_NAMES}
do
get_nfs_info ${resource}
if [ $? -ne 0 ]; then
# No resource information available.
${HA_LOG} "NFS: ${resource} parameters not present in CDB";
ha_write_status_for_resource ${resource} ${HA_NOCFGINFO};
exit_script ${HA_NOCFGINFO};
fi
ha_get_field "${HA_STRING}" filesystem
if [ $? -ne 0 ]; then
# filesystem not available available.
${HA_LOG} "NFS: filesystem not present in CDB for resource $resource";
ha_write_status_for_resource ${resource} ${HA_NOCFGINFO};
exit_script ${HA_NOCFGINFO};
fi
fs="$HA_FIELD_VALUE";
# Check to see if the filesystem is mounted
HA_CMD="mount | grep ${fs} >/dev/null 2>&1"
ha_execute_cmd "check to see if $fs is mounted"
if [ $? -ne 0 ]; then
${HA_LOG} "NFS: ${fs} not mounted";
ha_write_status_for_resource ${resource} ${HA_CMD_FAILED};
exit_script $HA_CMD_FAILED;
fi
# stat the filesystem
HA_CMD="fs_stat -r ${resource} >/dev/null 2>&1";
ha_execute_cmd "stat mount point $resource"
if [ $? -ne 0 ]; then
${HA_LOG} "NFS: cannot stat ${resource} NFS export point";
ha_write_status_for_resource ${resource} ${HA_CMD_FAILED};
exit_script $HA_CMD_FAILED;
fi
# check the filesystem is exported
showmount -e | grep "${resource} " >/dev/null 2>&1
if [ $? -ne 0 ]; then
${HA_LOG} "NFS: failed to find ${resource} in exported filesystem list:-"
${HA_LOG} "`showmount -e`"
ha_write_status_for_resource ${resource} ${HA_CMD_FAILED}
exit_script ${HA_CMD_FAILED}
fi
# check the NFS daemon is still alive and responding
exec_rpcinfo;
if [ $? -ne 0 ]; then
${HA_LOG} "NFS: exec_rpcinfo failed";
ha_write_status_for_resource ${resource} ${HA_CMD_FAILED}
exit_script $HA_CMD_FAILED
fi
# Check the stats ?
# To Be Done... but there is no nfsstat command
# for the user space NFS daemon.
ha_write_status_for_resource $resource $HA_SUCCESS;
done
} |
The NFS exclusive script determines whether the file system is already exported. The check made by an exclusive script can be more expensive than a monitor check. Linux FailSafe uses this script to determine if resources are running on a node in the cluster, and to thereby prevent starting resources on multiple nodes in the cluster.
Following is an example from the NFS exclusive script:
# Check if the nfs resource is running in the local node. This check can
# more intrusive than the monitor check. This check is used to determine
# if the resource has to be started on a machine in the cluster.
# Return HA_NOT_RUNNING if the resource is not running in the local node
# and HA_RUNNING if the resource is running in the local node
# The list of nfs resources passed as input is in variable
# $HA_RES_NAMES
#
exclusive_nfs()
{
${HA_DBGLOG} "Entry: exclusive_nfs()";
# for all resources passed as parameter
for resource in ${HA_RES_NAMES}
do
get_nfs_info $resource
if [ $? -ne 0 ]; then
# No resource information available
${HA_LOG} "NFS: $resource parameters not present in CDB";
ha_write_status_for_resource ${resource} ${HA_NOCFGINFO};
exit_script ${HA_NOCFGINFO};
fi
# Check if resource is already exported by the NFS server
showmount -e | grep "${resource} " >/dev/null 2>&1
if [ $? -eq 0 ];then
ha_write_status_for_resource ${resource} ${HA_RUNNING};
ha_print_exclusive_status ${resource} ${HA_RUNNING};
else
ha_write_status_for_resource ${resource} ${HA_NOT_RUNNING};
ha_print_exclusive_status ${resource} ${HA_NOT_RUNNING};
fi
done
} |
The NFS restart script exports the specified export-point with the specified export-options.
Following is an example from the restart script for NFS:
# Restart nfs resource
# Return HA_SUCCESS if nfs resource failed over successfully or
# return HA_CMD_FAILED if nfs resource could not be failed over locally.
# The list of nfs resources passed as input is in variable
# $HA_RES_NAMES
#
restart_nfs()
{
${HA_DBGLOG} "Entry: restart_nfs()";
# for all nfs resources passed as parameter
for resource in ${HA_RES_NAMES}
do
get_nfs_info $resource
if [ $? -ne 0 ]; then
${HA_LOG} "NFS: $resource parameters not present in CDB";
ha_write_status_for_resource ${resource} ${HA_NOCFGINFO};
exit_script ${HA_NOCFGINFO};
fi
ha_get_field "${HA_STRING}" export-info
if [ $? -ne 0 ]; then
${HA_LOG} "NFS: export-info not present in CDB for resource $resource";
ha_write_status_for_resource ${resource} ${HA_NOCFGINFO};
exit_script ${HA_NOCFGINFO};
fi
export_opts="$HA_FIELD_VALUE"
# Note: the export_dir command will check wether this directory
# is already exported or not.
HA_CMD="export_dir ${resource} ${export_opts}";
ha_execute_cmd "export $resource directories to NFS clients";
if [ $? -ne 0 ]; then
${HA_LOG} "NFS: could not export resoure ${resource}"
ha_write_status_for_resource ${resource} ${HA_CMD_FAILED};
exit_script ${HA_CMD_FAILED};
else
ha_write_status_for_resource ${resource} ${HA_SUCCESS};
fi
done
} |