]>
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 ER |
31 | # Stop blogd before umounting /var |
32 | if [ -x /sbin/blogd ] && ! is_no "$RC_BOOTLOG"; then | |
33 | killall -QUIT blogd | |
34 | fi | |
35 | ||
36 | ||
74c57003 AM |
37 | # check for other processes. |
38 | # there could be none if all services were terminated properly | |
39 | # pgrep -g 0 requires procps >= 3.2.6-1.1 | |
40 | pids=$(pgrep -g 0 -l -v | grep -v '^1 ') | |
41 | if [ -n "$pids" ]; then | |
42 | run_cmd "Sending all processes the TERM signal" killall5 -15 | |
43 | fi | |
44 | ||
45 | pids=$(pgrep -g 0 -l -v | grep -v '^1 ') | |
46 | if [ -n "$pids" ]; then | |
47 | sleep 5 | |
48 | run_cmd "Sending all processes the KILL signal" killall5 -9 | |
49 | fi | |
791f7cd2 JR |
50 | |
51 | # Write to wtmp file before unmounting /var | |
1822a5a6 | 52 | halt -w |
791f7cd2 | 53 | |
1aaf8c92 JR |
54 | if ! is_yes "$VSERVER"; then |
55 | # Turn off swap, then unmount file systems. | |
56 | run_cmd "Turning off swap" swapoff -a | |
7d7fd6c1 | 57 | |
1aaf8c92 | 58 | [ -x /etc/rc.d/rc.acct ] && /etc/rc.d/rc.acct stop |
791f7cd2 | 59 | |
1aaf8c92 JR |
60 | if [ -x /sbin/quotaoff ]; then |
61 | run_cmd "Turning off quotas for local filesystems" /sbin/quotaoff -a | |
62 | fi | |
2eec3807 | 63 | |
cc10e704 JR |
64 | # Unmount file systems, killing processes if we have to. |
65 | sig=-15 | |
66 | retry=3 | |
67 | force= | |
defac991 | 68 | remaining=$(awk '!/(^#| proc | loopfs | devfs | devpts | shm | iso9660 | ramfs | tmpfs | sysfs | securityfs | squashfs |^none|^\/dev\/root| \/ )/ {print $2}' /proc/mounts) |
2a57d1ce ER |
69 | while [ -n "$remaining" -a "$retry" -gt 0 ]; do |
70 | show "Unmounting file systems"; busy | |
8cf0be79 | 71 | ERRORS=$(umount -a $force -t noproc,devfs 2>&1); rc=$? |
2a57d1ce ER |
72 | |
73 | # we might had unmounted /usr, recheck $TPUT availability | |
74 | # but well. we need tput only for show() and busy() (ok() and fail() messages are already cached) | |
75 | # TODO: look ahead the messages? | |
76 | if is_yes "$TPUT"; then | |
77 | TPUT= | |
78 | rc_gettext_init | |
79 | fi | |
80 | ||
81 | if [ $rc = 0 ]; then | |
cc10e704 JR |
82 | ok |
83 | else | |
84 | fail | |
85 | [ -n "$ERRORS" ] && echo "$ERRORS" | |
86 | fi | |
5e6dfc29 | 87 | |
cc10e704 | 88 | sleep 2 |
defac991 | 89 | remaining=$(awk '!/(^#| proc | loopfs | devfs | devpts | shm | iso9660 | ramfs | tmpfs | sysfs | securityfs | squashfs |^none|^\/dev\/root| \/ )/ {print $2}' /proc/mounts) |
cc10e704 JR |
90 | [ -z "$remaining" ] && break |
91 | /sbin/fuser -k -m $sig $remaining > /dev/null | |
92 | sleep 5 | |
93 | retry=$(($retry-1)) | |
94 | sig=-9 | |
95 | force="-f" | |
96 | done | |
97 | ||
98 | run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro / | |
99 | ||
100 | if is_yes "$EVMS_LVM" || [ -x /sbin/vgscan -a -x /sbin/vgchange ]; then | |
101 | lvmversion=$(/sbin/vgchange --version 2>/dev/null | awk '{gsub("vgchange: Logical Volume Manager ",""); gsub("LVM version: ",""); gsub(/\..*/,"");print $1; exit}') | |
102 | if [ "$lvmversion" = "2" ] ; then | |
103 | lvmignorelock="--ignorelockingfailure" | |
104 | else | |
105 | lvmignorelock="" | |
106 | fi | |
107 | run_cmd "Stopping LVM volume groups" /sbin/vgchange -a n $lvmignorelock | |
41781ded | 108 | fi |
41781ded | 109 | |
cc10e704 JR |
110 | goraidtab=1 |
111 | if [ -x /sbin/mdadm -a -f /etc/mdadm.conf ]; then | |
112 | if (grep -qE "^([[:blank:]]|)ARRAY[[:blank:]]" /etc/mdadm.conf 2>/dev/null); then | |
5e6dfc29 JR |
113 | run_cmd "Turning off RAID devices" /sbin/mdadm --stop --scan |
114 | rc=$? | |
115 | [ "$rc" -eq 0 ] && goraidtab=0 | |
cc10e704 | 116 | fi |
8fb3abd8 | 117 | fi |
5e6dfc29 | 118 | |
cc10e704 JR |
119 | # turn off raid |
120 | if [ -x /sbin/raidstop -a -f /etc/raidtab -a "$goraidtab" -eq 1 ]; then | |
121 | # we can not use raidstop -a here because this will only stop | |
122 | # devices listed in the default config file which is not always | |
123 | # the case. So we look only for the active raid devices | |
124 | if [ -f /proc/mdstat ] ; then | |
125 | mddevs=$(awk '/^md.* active/ {print $1}' /proc/mdstat) | |
126 | for mddev in $mddevs ; do | |
127 | show "Turning off RAID for %s" "$mddev" | |
128 | daemon /sbin/raidstop /dev/$mddev | |
129 | done | |
130 | unset mddev mddevs | |
131 | fi | |
132 | # runcmd "Turning off RAID" /sbin/raidstop -a | |
791f7cd2 | 133 | fi |
791f7cd2 | 134 | |
cc10e704 JR |
135 | show "Remounting remaining filesystems ro mode"; busy |
136 | if ( mount | awk '/ext2|ext3|reiserfs|xfs|jfs/ { print $3 }' | \ | |
5e6dfc29 | 137 | while read line; do |
cc10e704 JR |
138 | mount -n -o ro,remount $line; done ); then |
139 | ok | |
140 | else | |
141 | fail | |
142 | fi | |
2e33f3ce JR |
143 | _rebootwhat="system" |
144 | else | |
145 | _rebootwhat="vserver" | |
146 | fi | |
147 | ||
d0f42664 | 148 | if [ "$runlevel" = "0" ] ; then |
2e33f3ce | 149 | show "The $_rebootwhat is halted"; ok |
d0f42664 | 150 | [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok) |
bc451b91 | 151 | |
cc10e704 | 152 | if [ -x /sbin/poweroff-ups -a -f /etc/killpower -a -f /etc/sysconfig/ups ] ; then |
5e6dfc29 JR |
153 | . /etc/sysconfig/ups |
154 | is_yes "$POWEROFF_UPS" && /sbin/poweroff-ups | |
cc10e704 JR |
155 | fi |
156 | [ "$previous" != "unknown" ] && eval halt -d -p | |
d0f42664 | 157 | else |
2e33f3ce | 158 | show "Please stand by while rebooting the $_rebootwhat"; ok |
d0f42664 | 159 | [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok) |
6dde00e1 | 160 | [ -x /sbin/kexec ] && /sbin/kexec -e |
cc10e704 | 161 | [ "$previous" != "unknown" ] && eval reboot -d |
d0f42664 JR |
162 | fi |
163 | ||
d893fe33 | 164 | # This must be last line ! |
cc10e704 | 165 | # vi:syntax=sh |