Subversion Repositories livecd

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
runcmd() {
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_get_remaining() {
26
	awk '$2 ~ /^\/$|^\/proc|^\/dev/{next}
27
	     $3 == "tmpfs" || $3 == "proc" {print $2 ; next}
28
	     /(^#|loopfs|autofs|sysfs|devfs|^none|^\/dev\/ram|^\/dev\/root)/ {next}
29
	     {print $2}' /proc/mounts
30
}
31
 
32
# See how we were called.
33
case "$0" in
34
   *halt)
35
	message=$"Halting system..."
36
	command="/sbin/halt"
37
	;;
38
   *reboot)
39
	message=$"Please stand by while rebooting the system..."
40
	command="/sbin/reboot"
41
	;;
42
   *)
43
	echo $"$0: call me as 'halt' or 'reboot' please!"
44
	exit 1
45
	;;
46
esac
47
case "$1" in
48
   *start)
49
   	;;
50
   *)
51
	echo $"Usage: $0 {start}"
52
	exit 1
53
	;;
54
esac
55
 
56
# Kill all processes.
57
[ "${BASH+bash}" = bash ] && enable kill
58
 
59
runcmd $"Sending all processes the TERM signal..." /sbin/killall5 -15
60
sleep 5
61
runcmd $"Sending all processes the KILL signal..."  /sbin/killall5 -9
62
 
63
# Write to wtmp file before unmounting /var
64
/sbin/halt -w
65
 
66
# Save mixer settings, here for lack of a better place.
67
grep -q "\(alsa\)" /proc/devices
68
if [ $? = 0 -a -x /usr/sbin/alsactl ]; then
69
   runcmd $"Saving mixer settings" alsactl store
70
fi
71
 
72
# Save random seed
73
touch /var/lib/random-seed
74
chmod 600 /var/lib/random-seed
75
runcmd $"Saving random seed: " dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=512 2>/dev/null
76
 
77
# Sync the system clock.
78
ARC=0
79
SRM=0
80
UTC=0
81
 
82
if [ -f /etc/sysconfig/clock ]; then
83
   . /etc/sysconfig/clock
84
 
85
   # convert old style clock config to new values
86
   if [ "${CLOCKMODE}" = "GMT" ]; then
87
      UTC=true
88
   elif [ "${CLOCKMODE}" = "ARC" ]; then
89
      ARC=true
90
   fi
91
fi
92
 
93
CLOCKDEF=""
94
CLOCKFLAGS="$CLOCKFLAGS --systohc"
95
 
96
case "$UTC" in
97
   yes|true)
98
	CLOCKFLAGS="$CLOCKFLAGS -u";
99
	CLOCKDEF="$CLOCKDEF (utc)";
100
	;;
101
   no|false)
102
	CLOCKFLAGS="$CLOCKFLAGS --localtime";
103
	CLOCKDEF="$CLOCKDEF (localtime)";
104
	;;
105
esac
106
 
107
case "$ARC" in
108
   yes|true)
109
	CLOCKFLAGS="$CLOCKFLAGS -A";
110
	CLOCKDEF="$CLOCKDEF (arc)";
111
	;;
112
esac
113
case "$SRM" in
114
   yes|true)
115
	CLOCKFLAGS="$CLOCKFLAGS -S";
116
	CLOCKDEF="$CLOCKDEF (srm)";
117
	;;
118
esac
119
 
120
runcmd $"Syncing hardware clock to system time" /sbin/hwclock $CLOCKFLAGS
121
 
122
# Turn off swap, then unmount file systems.
123
[ -f /proc/swaps ] && SWAPS=`awk '! /^Filename/ { print $1 }' /proc/swaps`
124
[ -n "$SWAPS" ] && runcmd $"Turning off swap: " swapoff $SWAPS
125
 
126
[ -x /sbin/quotaoff ] && runcmd $"Turning off quotas: " /sbin/quotaoff -aug
127
 
128
# Unmount file systems, killing processes if we have to.
129
# Unmount loopback stuff first
130
remaining=`awk '!/^#/ && $1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts`
131
devremaining=`awk '!/^#/ && $1 ~ /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts`
132
[ -n "$remaining" ] && {
133
	sig=
134
	retry=3
135
	while [ -n "$remaining" -a "$retry" -gt 0 ]
136
	do
137
		if [ "$retry" -lt 3 ]; then
138
			runcmd $"Unmounting loopback filesystems (retry):" umount $remaining
139
		else
140
			runcmd $"Unmounting loopback filesystems: " umount $remaining
141
		fi
142
		for dev in $devremaining ; do
143
			losetup $dev > /dev/null 2>&1 && \
144
				runcmd $"Detaching loopback device $dev: " losetup -d $dev
145
		done
146
		remaining=`awk '!/^#/ && $1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts`
147
		devremaining=`awk '!/^#/ && $1 ~ /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts`
148
		[ -z "$remaining" ] && break
149
		/sbin/fuser -k -m $sig $remaining >/dev/null
150
		sleep 5
151
		retry=$(($retry -1))
152
		sig=-9
153
	done
154
}
155
 
156
# Unmount RPC pipe file systems
157
sig=
158
retry=3
159
remaining=`awk '!/^#/ && $3 ~ /^rpc_pipefs$/ || $3 ~ /^rpc_svc_gss_pipefs$/ {print $2}' /proc/mounts`
160
 
161
while [ -n "$remaining" -a "$retry" -gt 0 ]
162
do
163
	if [ "$retry" -lt 3 ]; then
164
		runcmd $"Unmounting pipe file systems (retry): "  umount -f $remaining
165
	else
166
		runcmd $"Unmounting pipe file systems: "  umount -f $remaining
167
	fi
168
	sleep 2
169
	remaining=`awk '!/^#/ && $3 ~ /^rpc_pipefs$/ || $3 ~ /^rpc_svc_gss_pipefs$/ {print $2}' /proc/mounts`
170
	[ -z "$remaining" ] && break
171
	/sbin/fuser -k -m $sig $remaining >/dev/null
172
	sleep 5
173
	retry=$(($retry-1))
174
	sig=-9
175
done
176
 
177
sig=
178
retry=3
179
remaining=`halt_get_remaining | sort -r`
180
 
181
while [ -n "$remaining" -a "$retry" -gt 0 ]
182
do
183
	if [ "$retry" -lt 3 ]; then
184
		LANG=C runcmd $"Unmounting file systems (retry): "  umount -f $remaining
185
	else
186
		LANG=C runcmd $"Unmounting file systems: "  umount -f $remaining
187
	fi
188
	sleep 2
189
	remaining=`halt_get_remaining | sort -r`
190
	[ -z "$remaining" ] && break
191
	/sbin/fuser -k -m $sig $remaining >/dev/null
192
	sleep 5
193
	retry=$(($retry-1))
194
	sig=-9
195
done
196
[ -f /proc/bus/usb/devices ] && umount /proc/bus/usb
197
 
198
# remove the crash indicator flag
199
rm -f /.autofsck
200
 
201
# Try all file systems other than root and RAM disks, one last time.
202
mount |  awk '!/( \/ |^\/dev\/root|^\/dev\/ram| \/proc )/ { print $3 }' | \
203
  while read line; do
204
    umount -f $line
205
done
206
 
207
# Remount read only anything that's left mounted.
208
# echo $"Remounting remaining filesystems readonly"
209
mount | awk '{ print $3 }' | while read line; do
210
    mount -n -o ro,remount $line
211
done
212
 
213
# Now halt or reboot.
214
echo $"$message"
215
if [ -f /fastboot ]; then
216
 echo $"On the next boot fsck will be skipped."
217
elif [ -f /forcefsck ]; then
218
 echo $"On the next boot fsck will be forced."
219
fi
220
 
221
if [ "$command" = /sbin/halt -a -r /etc/ups/upsmon.conf -a -f /etc/killpower -a -f /etc/sysconfig/ups ] ; then
222
	. /etc/sysconfig/ups
223
	if [ "$SERVER" = "yes" -a "$MODEL" = "upsdrvctl" ] ; then
224
		/sbin/upsdrvctl shutdown
225
	elif [ "$SERVER" = "yes" -a "$MODEL" != "NONE" -a -n "$MODEL" -a -n "$DEVICE" ] ; then
226
		$MODEL $OPTIONS_HALT -k $DEVICE
227
	fi
228
fi
229
 
230
if [ -x /sbin/halt.local ]; then
231
   /sbin/halt.local
232
fi
233
 
234
HALTARGS="-i -d"
235
[ -f /poweroff -o ! -f /halt ] && HALTARGS="$HALTARGS -p"
236
 
237
exec $command $HALTARGS