#!/sbin/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:	@(#) /sbin/init.d/halt	1.50	1994-01-15
#
# Author:	Miquel van Smoorenburg <miquels@drinkel.nl.mugnet.org>
#
  # Don't terminate this script!
  trap "" SIGTERM

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

  # Find out how we were called.
  case "$0" in
	*halt)
		message="The system is halted"
		command="halt -d"
		what="Halt:"
		;;
	*reboot)
		message="Please stand by while rebooting the system..."
		command="reboot -d"
		what="Reboot:"
		;;
	*)
		echo "$0: call me as \"rc.halt\" or \"rc.reboot\" please!"
		exit 1
		;;
  esac

  # Write to wtmp file before unmounting /var
  halt -w

  # Kill all processes.
  echo "$what Sending all processes the TERM signal.."
  /sbin/killall -15
  sleep 5
  echo "$what Sending all processes the KILL signal.."
  /sbin/killall -9

  # Turn off swap, then unmount file systems.
  echo "$what Turning off swap"
  sync ; sync ; sync
  swapoff -a

  echo "$what Unmounting file systems"
  sync ; sync ; sync
  /bin/umount -at nonfs
  /bin/mount -no remount,ro /
  sync ; sleep 1 ; sync

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

sync
exec $command
