#!/bin/ksh
# @(#)76	1.4.1.3  src/avs/fs/mmfs/samples/nfscluster/cleanup, mmfs, avs_rgpfs24, rgpfs24s005a 6/26/06 15:16:12
#
# cleanup
#
##############################################################################
if [ ! -f /var/mmfs/etc/nfsfuncs ]; then
    echo "$0: Can't find NFS functions in /var/mmfs/etc"
    exit 0
fi
. /var/mmfs/etc/nfsfuncs

# Check for locks
locks=$( cat /proc/locks | grep "POSIX" )
if [ "$locks" != "" ]; then
	secs=45
else
	secs=3
fi
if [[ "$REBOOT" == "1" &&  -f /tmp/ha-nfs-reboot ]]; then
	echo "$0: rebooting this node in $secs seconds"
	sleep $secs
	/usr/lpp/mmfs/bin/mmfsadm cleanup
	debuglog rm /tmp/ha-nfs-reboot
	reboot
	exit
fi

msg "$0 waiting $secs seconds before starting NLM cleanup"
sleep $secs
msg "$0 starting NLM cleanup"

# Terminate all NFS service.
nfsService terminate

FSTYPE=gpfs
UMOUNTALL="/bin/umount -a"
# Note: Do not redirect stderr on Linux umount.
STDERR_REDIRECT=""

# Busy file systems will not unmount.
$(eval $UMOUNTALL -t $FSTYPE $STDERR_REDIRECT)

# Try forced unmount.
$UMOUNTALL -f -t $FSTYPE

# Do any commands here to clean up local state
# before the GPFS daemon restarts.

# Clean GPFS
/usr/lpp/mmfs/bin/mmfsadm cleanup
/usr/lpp/mmfs/bin/mmfsenv -u


return 0

