#!/bin/ksh
#
#Copyright (C) 1997 Sun Microsystems, Inc.
#pragma ident   "@(#)nfs_fm_stop.sh 1.5 98/04/22"

##########################################################################
# nfs_fm_stop.sh                                                         #
#                                                                        #
# This file contains routines for stopping NFS fault monitors            #
# This scripts then kills nfs_fm_local_restart process                   #
# It is invoked by the framework (FM_STOP) method with the  following    #
# parameters.                                                            #
# <List of Logical Host Names Mastered On this Node>                     #
# <List of Logical Host Names Not Mastered On this Node>                 #
# <timeout-Value>                                                        #
# None of these parameters are used by the script                        #
#                                                                        #
# Action:                                                                #
#    1. Uses pmfadm -s to stop all the related process                   #
#                                                                        #
##########################################################################
CLUSTERBIN=/opt/SUNWcluster/bin/
FMBIN=/opt/SUNWcluster/ha/nfs/
MASTERED_LIST=`echo $1 | /usr/bin/tr ',' ' '`
NOT_MASTERED_LIST=`echo $2 | /usr/bin/tr ',' ' '`
TIMEOUT=$3

#
# Use use pmfadm to kill the process since we know the tag of the pmfadm.
# (Tag is registered in nfs_fm_start,, so should use the same thing,
# changes done there should be carried out here.)
#
# Using SIGUSR1 so that process exit gracefully.
#
SIGUSR1=16

#
# The semantics of STOP method is as follows:
#
# 1. Mastered List is the List it is supposed to master.
#	(hence Leave it as it )
#
# 2. Not-Mastered List is the List that this is not supposed
#    to master. Hence we have to use pmfadm -s on this logical
#    host.


# 
# Commented Out.
#	for i in `echo ${MASTERED_LIST}`
#	do
#        	${CLUSTERBIN}/pmfadm -s "nfs_probe_local_${i}" \
#				${SIGUSR1}
#	done
#

# for Not Mastered List.

for i in `echo ${NOT_MASTERED_LIST}`
do
        ${CLUSTERBIN}/pmfadm -s "nfs_probe_${i}" \
			${SIGUSR1} 2>/dev/null
done

#
# wait for sometime so that processes are given a chance to clear the
# mess.
sleep 5
 
#
# send kill signal to the remaining processes.
#
for i in `echo ${NOT_MASTERED_LIST}`
do
        ${CLUSTERBIN}/pmfadm -k "nfs_probe_${i}" 2>/dev/null
done



# If we do not have anything in MASTERED_LIST in nfs_fm_stop
# it means that we do have any logical host mastered.
# Hence stop the local/restart. since we are not using pmfadm
# we have to kill them.
if [ -z "${MASTERED_LIST}" ]; then
    pids=`/usr/bin/ps -ef | /usr/bin/grep -w nfs_probe_local_restart | \
		/usr/bin/grep -v grep | /usr/bin/awk ' { print $2 } '`

    if [ ! -z ${pids} ]; then
	kill -15 ${pids}
    fi
fi

#
# nfs_probe_loghost would have umount all the fileyssystem if possible.
# To be sure call nfs_umount_all here.
#
${FMBIN}/nfs_umount_all "${NOT_MASTERED_LIST}"

exit 0
