]>
Commit | Line | Data |
---|---|---|
791f7cd2 JR |
1 | #!/bin/sh |
2 | # | |
af55fe6b | 3 | # shutdown Common script for system halt/reboot. |
791f7cd2 | 4 | # |
5e6dfc29 | 5 | # Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org> |
791f7cd2 | 6 | # |
ec8b15cb | 7 | # $Id$ |
791f7cd2 JR |
8 | |
9 | # Set the path. | |
10 | PATH=/sbin:/bin:/usr/bin:/usr/sbin | |
11 | ||
de160ea3 AM |
12 | # move to root dir |
13 | cd / | |
14 | ||
d84e0c78 JR |
15 | IN_SHUTDOWN=yes |
16 | ||
791f7cd2 JR |
17 | . /etc/rc.d/init.d/functions |
18 | ||
b6509675 AM |
19 | # avoid keyboard interruption |
20 | trap "echo" INT SEGV QUIT TERM | |
21 | set +e | |
22 | ||
23 | rc_splash "reboot" | |
24 | ||
791f7cd2 JR |
25 | # Kill all processes. |
26 | [ "${BASH+bash}" = bash ] && enable kill | |
27 | ||
d0f42664 | 28 | runlevel=$1 |
cc10e704 | 29 | previous=$2 |
d0f42664 | 30 | |
0868c9a6 | 31 | # Stop blogd before umounting /var |
b171122f ER |
32 | if [ -x /sbin/blogd ]; then |
33 | killall -q -QUIT blogd | |
0868c9a6 ER |
34 | fi |
35 | ||
74c57003 AM |
36 | # check for other processes. |
37 | # there could be none if all services were terminated properly | |
38 | # pgrep -g 0 requires procps >= 3.2.6-1.1 | |
39 | pids=$(pgrep -g 0 -l -v | grep -v '^1 ') | |
40 | if [ -n "$pids" ]; then | |
41 | run_cmd "Sending all processes the TERM signal" killall5 -15 | |
42 | fi | |
43 | ||
44 | pids=$(pgrep -g 0 -l -v | grep -v '^1 ') | |
45 | if [ -n "$pids" ]; then | |
46 | sleep 5 | |
47 | run_cmd "Sending all processes the KILL signal" killall5 -9 | |
48 | fi | |
791f7cd2 JR |
49 | |
50 | # Write to wtmp file before unmounting /var | |
1822a5a6 | 51 | halt -w |
791f7cd2 | 52 | |
1aaf8c92 JR |
53 | if ! is_yes "$VSERVER"; then |
54 | # Turn off swap, then unmount file systems. | |
55 | run_cmd "Turning off swap" swapoff -a | |
7d7fd6c1 | 56 | |
1aaf8c92 | 57 | [ -x /etc/rc.d/rc.acct ] && /etc/rc.d/rc.acct stop |
791f7cd2 | 58 | |
1aaf8c92 JR |
59 | if [ -x /sbin/quotaoff ]; then |
60 | run_cmd "Turning off quotas for local filesystems" /sbin/quotaoff -a | |
61 | fi | |
2eec3807 | 62 | |
6b30816c ER |
63 | # grab kexec_loaded state before we umount /sys |
64 | kexec_loaded=`cat /sys/kernel/kexec_loaded 2>/dev/null` | |
65 | ||
cc10e704 JR |
66 | # Unmount file systems, killing processes if we have to. |
67 | sig=-15 | |
68 | retry=3 | |
69 | force= | |
4cc198ff JR |
70 | if [ -z "$UMOUNT_IGNORE" ]; then |
71 | UMOUNT_IGNORE="/" | |
72 | else | |
73 | UMOUNT_IGNORE="/ $UMOUNT_IGNORE" | |
74 | fi | |
75 | remaining=$(awk -v ig="^($UMOUNT_IGNORE)$" 'BEGIN { gsub(/[\t ]+/, "|", ig); } \ | |
76 | $3 !~ /^(proc|loopfs|devpts|shm|iso9660|ramfs|tmpfs|sysfs|securityfs|squashfs)$/ \ | |
2850ca3d | 77 | && $1 !~ /^(none|\/dev\/root)$/ \ |
4cc198ff | 78 | && $2 !~ ig {print $2}' /proc/mounts) |
2a57d1ce ER |
79 | while [ -n "$remaining" -a "$retry" -gt 0 ]; do |
80 | show "Unmounting file systems"; busy | |
34c624e7 | 81 | ERRORS=$(umount -a $force -t noproc 2>&1); rc=$? |
2a57d1ce ER |
82 | |
83 | # we might had unmounted /usr, recheck $TPUT availability | |
84 | # but well. we need tput only for show() and busy() (ok() and fail() messages are already cached) | |
85 | # TODO: look ahead the messages? | |
86 | if is_yes "$TPUT"; then | |
87 | TPUT= | |
88 | rc_gettext_init | |
89 | fi | |
90 | ||
91 | if [ $rc = 0 ]; then | |
cc10e704 JR |
92 | ok |
93 | else | |
94 | fail | |
95 | [ -n "$ERRORS" ] && echo "$ERRORS" | |
96 | fi | |
5e6dfc29 | 97 | |
cc10e704 | 98 | sleep 2 |
4cc198ff JR |
99 | remaining=$(awk -v ig="^($UMOUNT_IGNORE)$" 'BEGIN { gsub(/[\t ]+/, "|", ig); } \ |
100 | $3 !~ /^(proc|loopfs|devpts|shm|iso9660|ramfs|tmpfs|sysfs|securityfs|squashfs)$/ \ | |
2850ca3d | 101 | && $1 !~ /^(none|\/dev\/root)$/ \ |
4cc198ff | 102 | && $2 !~ ig {print $2}' /proc/mounts) |
cc10e704 | 103 | [ -z "$remaining" ] && break |
4b0d64e2 | 104 | fuser -k -m $sig $remaining > /dev/null |
cc10e704 JR |
105 | sleep 5 |
106 | retry=$(($retry-1)) | |
107 | sig=-9 | |
108 | force="-f" | |
109 | done | |
110 | ||
111 | run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro / | |
112 | ||
0174ae89 ER |
113 | if is_yes "$EVMS_LVM" || [ -x /sbin/vgchange ]; then |
114 | lvmversion=$(LC_ALL=C /sbin/vgchange --version 2>/dev/null | awk '/LVM version:/{if ($3 >= 2) print "2"}') | |
cc10e704 JR |
115 | if [ "$lvmversion" = "2" ] ; then |
116 | lvmignorelock="--ignorelockingfailure" | |
117 | else | |
118 | lvmignorelock="" | |
119 | fi | |
120 | run_cmd "Stopping LVM volume groups" /sbin/vgchange -a n $lvmignorelock | |
41781ded | 121 | fi |
41781ded | 122 | |
cc10e704 JR |
123 | goraidtab=1 |
124 | if [ -x /sbin/mdadm -a -f /etc/mdadm.conf ]; then | |
62119804 | 125 | if grep -qE "^([[:blank:]]|)ARRAY[[:blank:]]" /etc/mdadm.conf 2>/dev/null; then |
9045fdf6 | 126 | /sbin/mdadm --stop --scan > /dev/null 2>&1 |
5e6dfc29 JR |
127 | rc=$? |
128 | [ "$rc" -eq 0 ] && goraidtab=0 | |
cc10e704 | 129 | fi |
8fb3abd8 | 130 | fi |
5e6dfc29 | 131 | |
cc10e704 JR |
132 | # turn off raid |
133 | if [ -x /sbin/raidstop -a -f /etc/raidtab -a "$goraidtab" -eq 1 ]; then | |
134 | # we can not use raidstop -a here because this will only stop | |
135 | # devices listed in the default config file which is not always | |
136 | # the case. So we look only for the active raid devices | |
137 | if [ -f /proc/mdstat ] ; then | |
138 | mddevs=$(awk '/^md.* active/ {print $1}' /proc/mdstat) | |
139 | for mddev in $mddevs ; do | |
140 | show "Turning off RAID for %s" "$mddev" | |
141 | daemon /sbin/raidstop /dev/$mddev | |
142 | done | |
143 | unset mddev mddevs | |
144 | fi | |
145 | # runcmd "Turning off RAID" /sbin/raidstop -a | |
791f7cd2 | 146 | fi |
791f7cd2 | 147 | |
cc10e704 | 148 | show "Remounting remaining filesystems ro mode"; busy |
62119804 | 149 | if mount | awk '/ext2|ext3|reiserfs|xfs|jfs/ { print $3 }' | while read line; do mount -n -o ro,remount $line; done; then |
cc10e704 JR |
150 | ok |
151 | else | |
152 | fail | |
153 | fi | |
2e33f3ce JR |
154 | _rebootwhat="system" |
155 | else | |
156 | _rebootwhat="vserver" | |
157 | fi | |
158 | ||
6b496866 | 159 | if [ -f /etc/crypttab ] && ! is_empty_file /etc/crypttab; then |
8710c4b5 ER |
160 | . /etc/rc.d/init.d/cryptsetup |
161 | ||
162 | show "Stopping disk encryption" | |
878e1414 ER |
163 | halt_crypto && ok || fail |
164 | fi | |
165 | ||
d0f42664 | 166 | if [ "$runlevel" = "0" ] ; then |
2e33f3ce | 167 | show "The $_rebootwhat is halted"; ok |
62119804 ER |
168 | if [ -f /fastboot ]; then |
169 | show "On the next boot fsck will be skipped."; ok | |
170 | fi | |
bc451b91 | 171 | |
d0b6372d | 172 | if [ -f /etc/killpower -a -f /etc/sysconfig/ups ] ; then |
5e6dfc29 | 173 | . /etc/sysconfig/ups |
d0b6372d AM |
174 | if is_yes "$POWEROFF_UPS"; then |
175 | if [ -d /etc/ups.d ]; then | |
03ef5439 | 176 | for i in /etc/ups.d/*.sh; do |
d0b6372d AM |
177 | [ ! -f $i -o ! -x $i ] && continue |
178 | $i poweroff | |
179 | done | |
180 | fi | |
181 | [ -x /sbin/poweroff-ups ] && /sbin/poweroff-ups | |
182 | fi | |
cc10e704 | 183 | fi |
b1087329 | 184 | [ "$previous" != "unknown" ] && eval halt -d -p -f |
d0f42664 | 185 | else |
2e33f3ce | 186 | show "Please stand by while rebooting the $_rebootwhat"; ok |
62119804 ER |
187 | if [ -f /fastboot ]; then |
188 | show "On the next boot fsck will be skipped."; ok | |
189 | fi | |
69d7c00f | 190 | |
6b30816c ER |
191 | if [ -x /sbin/kexec ] && [ "$kexec_loaded" = "1" ]; then |
192 | show "Will now restart with kexec" | |
69d7c00f | 193 | /sbin/kexec -e |
6b30816c | 194 | fail |
69d7c00f ER |
195 | fi |
196 | ||
b1087329 | 197 | [ "$previous" != "unknown" ] && eval reboot -d -f |
d0f42664 | 198 | fi |