1 |
beyerle@PS |
1 |
#!/bin/bash
|
|
|
2 |
#
|
|
|
3 |
# halt This file is executed by init when it goes into runlevel
|
|
|
4 |
# 0 (halt) or runlevel 6 (reboot). It kills all processes,
|
|
|
5 |
# unmounts file systems and then either halts or reboots.
|
|
|
6 |
#
|
|
|
7 |
# Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
|
|
|
8 |
# Modified for RHS Linux by Damien Neil
|
|
|
9 |
#
|
|
|
10 |
|
|
|
11 |
NOLOCALE=1
|
|
|
12 |
. /etc/init.d/functions
|
|
|
13 |
|
|
|
14 |
action() {
|
|
|
15 |
echo -n "$1 "
|
|
|
16 |
shift
|
|
|
17 |
if [ "$BOOTUP" = "color" ]; then
|
|
|
18 |
"$@" && echo_success || echo_failure
|
|
|
19 |
else
|
|
|
20 |
"$@"
|
|
|
21 |
fi
|
|
|
22 |
echo
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
halt_crypto() {
|
|
|
26 |
fnval=0
|
|
|
27 |
while read dst src key; do
|
|
|
28 |
[ -z "$dst" -o "${dst#\#}" != "$dst" ] && continue
|
|
|
29 |
if [ -b "/dev/mapper/$dst" ]; then
|
|
|
30 |
if /sbin/dmsetup info "$dst" | grep -q '^Open count: *0$'; then
|
|
|
31 |
/sbin/cryptsetup remove "$dst"
|
|
|
32 |
else
|
|
|
33 |
fnval=1
|
|
|
34 |
fi
|
|
|
35 |
fi
|
|
|
36 |
done < /etc/crypttab
|
|
|
37 |
return $fnval
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
# See how we were called.
|
|
|
41 |
case "$0" in
|
|
|
42 |
*halt)
|
|
|
43 |
message=$"Halting system..."
|
|
|
44 |
command="/sbin/halt"
|
|
|
45 |
;;
|
|
|
46 |
*reboot)
|
|
|
47 |
message=$"Please stand by while rebooting the system..."
|
|
|
48 |
command="/sbin/reboot"
|
|
|
49 |
kexec_command="/sbin/kexec"
|
|
|
50 |
;;
|
|
|
51 |
*)
|
|
|
52 |
echo $"$0: call me as 'halt' or 'reboot' please!"
|
|
|
53 |
exit 1
|
|
|
54 |
;;
|
|
|
55 |
esac
|
|
|
56 |
case "$1" in
|
|
|
57 |
*start)
|
|
|
58 |
;;
|
|
|
59 |
*)
|
|
|
60 |
echo $"Usage: $0 {start}"
|
|
|
61 |
exit 1
|
|
|
62 |
;;
|
|
|
63 |
esac
|
|
|
64 |
|
|
|
65 |
# Kill all processes.
|
|
|
66 |
[ "${BASH+bash}" = bash ] && enable kill
|
|
|
67 |
|
|
|
68 |
action $"Sending all processes the TERM signal..." /sbin/killall5 -15
|
|
|
69 |
sleep 5
|
|
|
70 |
action $"Sending all processes the KILL signal..." /sbin/killall5 -9
|
|
|
71 |
|
|
|
72 |
# Write to wtmp file before unmounting /var
|
|
|
73 |
/sbin/halt -w
|
|
|
74 |
|
|
|
75 |
# Save mixer settings, here for lack of a better place.
|
|
|
76 |
grep -q "\(alsa\)" /proc/devices
|
|
|
77 |
if [ $? = 0 -a -x /usr/sbin/alsactl ]; then
|
|
|
78 |
action $"Saving mixer settings" alsactl store
|
|
|
79 |
fi
|
|
|
80 |
|
|
|
81 |
# Save random seed
|
|
|
82 |
touch /var/lib/random-seed
|
|
|
83 |
chmod 600 /var/lib/random-seed
|
|
|
84 |
action $"Saving random seed: " dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=512 2>/dev/null
|
|
|
85 |
|
|
|
86 |
# Sync the system clock.
|
|
|
87 |
ARC=0
|
|
|
88 |
SRM=0
|
|
|
89 |
UTC=0
|
|
|
90 |
|
|
|
91 |
if [ -f /etc/sysconfig/clock ]; then
|
|
|
92 |
. /etc/sysconfig/clock
|
|
|
93 |
|
|
|
94 |
# convert old style clock config to new values
|
|
|
95 |
if [ "${CLOCKMODE}" = "GMT" ]; then
|
|
|
96 |
UTC=true
|
|
|
97 |
elif [ "${CLOCKMODE}" = "ARC" ]; then
|
|
|
98 |
ARC=true
|
|
|
99 |
fi
|
|
|
100 |
fi
|
|
|
101 |
|
|
|
102 |
CLOCKDEF=""
|
|
|
103 |
CLOCKFLAGS="$CLOCKFLAGS --systohc"
|
|
|
104 |
|
|
|
105 |
case "$UTC" in
|
|
|
106 |
yes|true)
|
|
|
107 |
CLOCKFLAGS="$CLOCKFLAGS -u";
|
|
|
108 |
CLOCKDEF="$CLOCKDEF (utc)";
|
|
|
109 |
;;
|
|
|
110 |
no|false)
|
|
|
111 |
CLOCKFLAGS="$CLOCKFLAGS --localtime";
|
|
|
112 |
CLOCKDEF="$CLOCKDEF (localtime)";
|
|
|
113 |
;;
|
|
|
114 |
esac
|
|
|
115 |
|
|
|
116 |
case "$ARC" in
|
|
|
117 |
yes|true)
|
|
|
118 |
CLOCKFLAGS="$CLOCKFLAGS -A";
|
|
|
119 |
CLOCKDEF="$CLOCKDEF (arc)";
|
|
|
120 |
;;
|
|
|
121 |
esac
|
|
|
122 |
case "$SRM" in
|
|
|
123 |
yes|true)
|
|
|
124 |
CLOCKFLAGS="$CLOCKFLAGS -S";
|
|
|
125 |
CLOCKDEF="$CLOCKDEF (srm)";
|
|
|
126 |
;;
|
|
|
127 |
esac
|
|
|
128 |
|
|
|
129 |
[ -x /sbin/hwclock ] && action $"Syncing hardware clock to system time" /sbin/hwclock $CLOCKFLAGS
|
|
|
130 |
|
|
|
131 |
# Try to unmount tmpfs filesystems to avoid swapping them in. Ignore failures.
|
|
|
132 |
tmpfs=$(awk '$2 ~ /^\/($|proc|dev)/ { next; }
|
|
|
133 |
$3 == "tmpfs" { print $2; }' /proc/mounts | sort -r)
|
|
|
134 |
[ -n "$tmpfs" ] && fstab-decode umount $tmpfs 2>/dev/null
|
|
|
135 |
|
|
|
136 |
# Turn off swap, then unmount file systems.
|
|
|
137 |
[ -f /proc/swaps ] && SWAPS=`awk '! /^Filename/ { print $1 }' /proc/swaps`
|
|
|
138 |
if [ -n "$SWAPS" ]; then
|
|
|
139 |
action $"Turning off swap: " swapoff $SWAPS
|
|
|
140 |
for dst in $SWAPS; do
|
|
|
141 |
if [[ "$dst" =~ "^/dev/mapper" ]] \
|
|
|
142 |
&& [ "$(dmsetup status "$dst" | cut -d ' ' -f 3)" = crypt ]; then
|
|
|
143 |
backdev=$(/sbin/cryptsetup status "$dst" \
|
|
|
144 |
| awk '$1 == "device:" { print $2 }')
|
|
|
145 |
/sbin/cryptsetup remove "$dst"
|
|
|
146 |
# Leave partition with a blank plain-text swap
|
|
|
147 |
mkswap "$backdev" > /dev/null
|
|
|
148 |
fi
|
|
|
149 |
done
|
|
|
150 |
fi
|
|
|
151 |
|
|
|
152 |
[ -x /sbin/quotaoff ] && action $"Turning off quotas: " /sbin/quotaoff -aug
|
|
|
153 |
|
|
|
154 |
# Unmount file systems, killing processes if we have to.
|
|
|
155 |
# Unmount loopback stuff first
|
|
|
156 |
# __umount_loopback_loop
|
|
|
157 |
|
|
|
158 |
# Unmount RPC pipe file systems
|
|
|
159 |
# __umount_loop '$3 ~ /^rpc_pipefs$/ || $3 ~ /^rpc_svc_gss_pipefs$/ {print $2}' \
|
|
|
160 |
# /proc/mounts \
|
|
|
161 |
# $"Unmounting pipe file systems: " \
|
|
|
162 |
# $"Unmounting pipe file systems (retry): " \
|
|
|
163 |
# -f
|
|
|
164 |
|
|
|
165 |
# LANG=C __umount_loop '$2 ~ /^\/$|^\/proc|^\/dev/{next}
|
|
|
166 |
# $3 == "tmpfs" || $3 == "proc" {print $2 ; next}
|
112 |
beyerle@PS |
167 |
# /(loopfs|autofs|nfs|cifs|smbfs|ncpfs|sysfs|^none|^\/dev\/ram|^\/dev\/root$)/ {next}
|
1 |
beyerle@PS |
168 |
# {print $2}' /proc/mounts \
|
|
|
169 |
# $"Unmounting file systems: " \
|
|
|
170 |
# $"Unmounting file systems (retry): " \
|
|
|
171 |
# -f
|
|
|
172 |
|
|
|
173 |
[ -f /proc/bus/usb/devices ] && umount /proc/bus/usb
|
|
|
174 |
|
|
|
175 |
[ -f /etc/crypttab ] && \
|
|
|
176 |
LANG=C action $"Stopping disk encryption: " halt_crypto
|
|
|
177 |
|
|
|
178 |
# remove the crash indicator flag
|
|
|
179 |
rm -f /.autofsck
|
|
|
180 |
|
|
|
181 |
# Try all file systems other than root, essential filesystems and RAM disks,
|
|
|
182 |
# one last time.
|
|
|
183 |
awk '$2 !~ /\/(|dev|proc|selinux)$/ && $1 !~ /^\/dev\/ram/ { print $2 }' \
|
|
|
184 |
/proc/mounts | grep -v "/livecd/" | sort -r | \
|
|
|
185 |
while read line; do
|
|
|
186 |
fstab-decode umount -f $line
|
|
|
187 |
done
|
|
|
188 |
|
|
|
189 |
if [ -x /sbin/halt.local ]; then
|
|
|
190 |
/sbin/halt.local
|
|
|
191 |
fi
|
|
|
192 |
|
|
|
193 |
# Remount read only anything that's left mounted.
|
|
|
194 |
# echo $"Remounting remaining filesystems readonly"
|
|
|
195 |
mount | awk '{ print $3 }' | while read line; do
|
|
|
196 |
fstab-decode mount -n -o ro,remount $line
|
|
|
197 |
done
|
|
|
198 |
|
|
|
199 |
# Now halt or reboot.
|
|
|
200 |
echo $"$message"
|
|
|
201 |
if [ -f /fastboot ]; then
|
|
|
202 |
echo $"On the next boot fsck will be skipped."
|
|
|
203 |
elif [ -f /forcefsck ]; then
|
|
|
204 |
echo $"On the next boot fsck will be forced."
|
|
|
205 |
fi
|
|
|
206 |
|
|
|
207 |
if [ "$command" = /sbin/halt -a -r /etc/ups/upsmon.conf -a -f /etc/killpower -a -f /etc/sysconfig/ups ] ; then
|
|
|
208 |
. /etc/sysconfig/ups
|
|
|
209 |
if [ "$SERVER" = "yes" -a "$MODEL" = "upsdrvctl" ] ; then
|
|
|
210 |
/sbin/upsdrvctl shutdown
|
|
|
211 |
elif [ "$SERVER" = "yes" -a "$MODEL" != "NONE" -a -n "$MODEL" -a -n "$DEVICE" ] ; then
|
|
|
212 |
$MODEL $OPTIONS_HALT -k $DEVICE
|
|
|
213 |
fi
|
|
|
214 |
fi
|
|
|
215 |
|
|
|
216 |
# ------------------ LiveCD -------------------------
|
|
|
217 |
|
164 |
beyerle@PS |
218 |
# dir of mounted live system: /$MOUNTDIR/live
|
|
|
219 |
MOUNTDIR=livecd
|
|
|
220 |
|
|
|
221 |
# source functions of liblinuxlive
|
|
|
222 |
. /$MOUNTDIR/live/liblinuxlive
|
|
|
223 |
|
|
|
224 |
# root on NFS?
|
|
|
225 |
NFSROOT=$( cmdline_value nfsroot )
|
|
|
226 |
|
|
|
227 |
# noeject set?
|
|
|
228 |
NOEJECT=$( cmdline_parameter noeject )
|
|
|
229 |
|
|
|
230 |
# eject CDROM
|
|
|
231 |
# if CDROM is not on NFS and if noeject is not set
|
|
|
232 |
if [ ! $NFSROOT ] && [ ! $NOEJECT ]; then
|
|
|
233 |
echo -n "Ejecting CD-ROM ... "
|
166 |
beyerle@PS |
234 |
eject $( grep /$MOUNTDIR/live/livecd /proc/mounts | awk '{print $1}' )
|
1 |
beyerle@PS |
235 |
echo
|
|
|
236 |
fi
|
|
|
237 |
|
|
|
238 |
if [ "${command##*/}" = "reboot" ]; then
|
|
|
239 |
echo "Rebooting."; sleep 1
|
|
|
240 |
/livecd/live/bin/busybox reboot 2>/dev/null
|
|
|
241 |
reboot
|
|
|
242 |
else
|
|
|
243 |
echo "Poweroff."; sleep 1
|
|
|
244 |
/livecd/live/bin/busybox poweroff 2>/dev/null
|
|
|
245 |
poweroff
|
|
|
246 |
fi
|
|
|
247 |
|
|
|
248 |
# ------------------ LiveCD -------------------------
|
|
|
249 |
|
|
|
250 |
# First, try kexec. If that fails, fall back to rebooting the old way.
|
112 |
beyerle@PS |
251 |
[ -n "$kexec_command" ] && $kexec_command -e -x >& /dev/null
|
1 |
beyerle@PS |
252 |
|
|
|
253 |
HALTARGS="-d"
|
|
|
254 |
[ -f /poweroff -o ! -f /halt ] && HALTARGS="$HALTARGS -p"
|
|
|
255 |
|
|
|
256 |
exec $command $HALTARGS
|