summaryrefslogtreecommitdiffstats
path: root/rc/rc.shutdown
blob: 790117e7f55568e64da9eb596c9f142a9fa1ba67 (plain)
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
#!/bin/bash
#
# /etc/rc.shutdown: system shutdown script
#

# Load configuration
. /etc/rc.conf

# Set linefeed mode to avoid staircase effect
/bin/stty onlcr

echo "The system is coming down.  Please wait."

if [ "$PREVLEVEL" = "2" ]; then
	# Shutdown services
	if [ "${SERVICES[*]}" ]; then
		for service in "${SERVICES[@]}"; do
			R_SERVICES=($service ${R_SERVICES[@]})
		done
		for service in "${R_SERVICES[@]}"; do
			/etc/rc.d/$service stop &> /tmp/rc.$$
			/usr/bin/logger -t $service -f /tmp/rc.$$
			/bin/rm -f /tmp/rc.$$
		done
	fi
fi

# Terminate all processes
/sbin/killall5 -15
/bin/sleep 5
/sbin/killall5 -9

# Save random seed
/bin/dd if=/dev/urandom of=/var/lib/urandom/seed count=1 2> /dev/null

# Save system clock
/sbin/hwclock --systohc

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

# Turn off swap
/sbin/swapoff -a

# Unmount file systems
/bin/umount -a -r -t nosysfs,noproc
if [ -x /sbin/lvm ]; then
	/sbin/vgchange --ignorelockingfailure -a n
fi
/bin/umount -a -r

# Remount root filesystem read-only
/bin/mount -n -o remount,ro /

# Power off or reboot
if [ "$RUNLEVEL" = "0" ]; then
	/sbin/poweroff -d -f -i
else
	/sbin/reboot -d -f -i
fi

# End of file