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