#!/bin/sh
#
#    Copyright (c) 1996-2012 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

# Kill, restart and kill wdt is done to make sure we get another 30 secs
# window to complete unmounting and other cleanup.
echo "Disabling wdt: `date`"
${KILLALL} -TERM wdtd
/sbin/wdtd -p 60 -n 5 2> ${NULL} 
${KILLALL} -TERM wdtd

# kill all processes
/sbin/killall5

# unmount filesystems
echo "Unmounting all filesystems: `date`"
sleep 1
umount -a -f 
mount -n -o remount,ro /

# Now halt or reboot.
echo "$message `date`"
if [ -x /bin/partman -a $command = "reboot" ]; then
	/bin/partman -r
else
	eval $command -i -d -p
fi
