#! /bin/sh
#
# rc.halt	This file is executed by init when it goes into runlevel
#		0 (halt) or runlevel 6 (reboot). It kills all processes,
#		unmounts file systems and then either halts or reboots.
#
# Version:	@(#)/etc/rc.d/rc.halt	1.50	1994-01-15
#
# Author:	Miquel van Smoorenburg <miquels@drinkel.nl.mugnet.org>
#

  # Set the path.
  PATH=/sbin:/etc:/bin:/usr/bin

  # Find out how we were called.
  case "$0" in
	*0)
		message="The system is halted."
		command="halt"
		;;
	*6)
		message="Rebooting."
		command=reboot
		;;
	*)
		echo "$0: call me as \"rc.0\" or \"rc.6\" please!"
		exit 1
		;;
  esac

  # Kill all processes.
  echo
  echo "Sending all processes the TERM signal."
  kill -15 -1
  echo -n "Waiting for processes to terminate"
  for loop in 0 1 2 3 4 5 6 7 ; do
    sleep 1
    echo -n "."
  done
  echo
  echo "Sending all processes the KILL signal."
  kill -9 -1

  # Try to turn off quota and accounting.
  if [ -x /usr/sbin/quotaoff ]
  then
	echo "Turning off quota."
	/usr/sbin/quotaoff -a
  fi
  if [ -x /sbin/accton ]
  then
	echo "Turning off accounting."
	/sbin/accton
  fi

  # Before unmounting file systems write a reboot record to wtmp.
  halt -w

  # Turn off swap, then unmount file systems.
  echo "Turning off swap."
  swapoff -a
  echo "Unmounting file systems."
  umount -a
  # Don't remount UMSDOS root volumes:
  if [ ! "`mount | head -1 | cut -d ' ' -f 5`" = "umsdos" ]; then
    mount -n -o remount,ro /
  fi

  # Now halt or reboot.
  echo "$message"
#  [ -f /etc/fastboot ] && echo "On the next boot fsck will be skipped."
  eval $command -d
