#!/bin/sh
#
#    Copyright (c) 1996-2000 Brocade Communications Systems, Inc.
#    All rights reserved.
#
#    Original authors:
#      Miquel van Smoorenburg <miquels@drinkel.nl.mugnet.org>
#      Damien Niel, Red Hat Systems
#
#    Initialization script to halt/reboot the system.
#

# Source common library
. /etc/init.d/functions

case "$0" in
*halt)
    message="The system is halted"
    command="halt"
    ;;

*reboot)
    message="Please stand by while rebooting the system..."
    command="reboot"
    ;;

*)
    echo "$0: call me as \"rc.halt\" or \"rc.reboot\" please!"
    exit 1
    ;;
esac

if [ ! -f /tmp/.hafailover ]; then
	echo "`date '+%D %T'` Executing platform yield"
	#Executing platform yield which will shutdown ASIC  DMA
	/fabos/cliexec/platformyield

	#sleep 3
	echo "`date '+%D %T'` platform yield completed!"
fi

${KILLALL} -TERM wdtd
#echo "wdtd killed"
/sbin/killall5

#umounting individual FSes are for debugging purpose,is going to be temporary and
#will be reverted back after root cause has been identified
echo "`date '+%D %T'` Unmounting /mnt filesystem"
umount -f /mnt

echo "`date '+%D %T'` Unmounting /tmp filesystem"
umount -f /tmp

echo "`date '+%D %T'` Unmounting / filesystem"
umount -f /

#echo "`date '+%D %T'` Unmounting all filesystems."
#sleep 1
#umount -a -f
echo "`date '+%D %T'` Unmounted all filesystems."
mount -n -o remount,ro /


# Now halt or reboot.
echo "`date '+%D %T'` $message"

# Make sure to wait long enough for the above "message" comes up on the console in case halt is issued.
# This is needed for factory FCA screening tests to pass for Vesper.

SWBD=`sin | swbd 2> ${NULL}`

if [[("$SWBD" == "SWBD189") && ("$command" == "halt")]]; then
	sleep 3
fi

eval $command -i -d -p
