summaryrefslogtreecommitdiffstats
path: root/sbin/rc.0
blob: fb546de5353dc67f22de29bb9e67378e99954b01 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#! /bin/sh
#
# rc.6		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.6	1.50	1994-01-15
#
# Author:	Miquel van Smoorenburg <miquels@drinkel.nl.mugnet.org>
# Modified by:  Patrick J. Volkerding, <volkerdi@ftp.cdrom.com>
#

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

# If there are SystemV init scripts for this runlevel, run them.
if [ -x /sbin/init.d/sysvinit ]; then
	/sbin/init.d/sysvinit start 
fi

# Set linefeed mode to avoid staircase effect.
stty onlcr

echo "Running shutdown script $0:"

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

# Kill all processes.
# INIT is supposed to handle this entirely now, but this didn't always
# work correctly without this second pass at killing off the processes.
# Since INIT already notified the user that processes were being killed,
# we'll avoid echoing this info this time around.
if [ "$1" != "fast" ]; then # shutdown did not already kill all processes
	killall5 -15 
	sleep 5
	killall5 -9
fi

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

# Syncing data
sync

# Unmount any remote filesystems:
echo "Unmounting remote filesystems."
umount -na -tnfs 

# Turn off swap, then unmount local file systems.
echo "Turning off swap."
swapoff -a
echo "Unmounting local file systems."
# Don't remount UMSDOS root volumes:
if [ ! "`cat /proc/mounts | head -1 | cut -d ' ' -f 5`" = "umsdos" ]; then
	umount -na -t nonfs -t noproc
	echo "Remounting root filesystem read-only."
	mount -n -o remount,ro /
else
	umount -na -t nonfs -t noumsdos -t noproc
fi
# This never hurts:
sync

# Now halt (poweroff with APM kernels) or reboot.
if [ "$command" = "reboot" ]; then
	echo "Rebooting."
	reboot -f
else
	halt -f -p
fi