#! /bin/sh
#
# Copyright (c) 1998 Florian La Roche
#

if test "$1" != start ; then
	exit 0
fi

case "$0" in
    *halt)	message="The system is halted."
		command="poweroff"
		;;
    *reboot)	message="Please stand by while rebooting the system..."
		command="reboot"
		;;
    *)		echo "$0: call me as \"halt\" or \"reboot\" please!"
		exit 1
esac

# Write to wtmp file before unmounting /var
$command -w 

echo "Sending all processes the TERM signal..."
killall5 -15
sleep 4
echo "Sending all processes the KILL signal..."
killall5 -9
sync

echo "Turning off swap."
swapoff -a

echo "Unmounting file systems"
umount -at proc
umount -ar
if test -s /etc/mdtab -a -x /sbin/mdstop ; then
	/sbin/mdstop -a
fi

mount -no remount,ro /
if test $? -ne 0 ; then
	ps xuwa
	fuser -mv /
	sleep 20
fi
sync

echo $message
exec $command -d -f -i
