3 # shutdown Common script for system halt/reboot.
5 # Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
10 PATH=/sbin:/bin:/usr/bin:/usr/sbin
17 . /etc/rc.d/init.d/functions
19 # avoid keyboard interruption
20 trap "echo" INT SEGV QUIT TERM
26 [ "${BASH+bash}" = bash ] && enable kill
31 # Stop blogd before umounting /var
32 if [ -x /sbin/blogd ]; then
33 killall -q -QUIT blogd
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
44 pids=$(pgrep -g 0 -l -v | grep -v '^1 ')
45 if [ -n "$pids" ]; then
47 run_cmd "Sending all processes the KILL signal" killall5 -9
50 # Write to wtmp file before unmounting /var
53 if ! is_yes "$VSERVER"; then
54 # Turn off swap, then unmount file systems.
55 run_cmd "Turning off swap" swapoff -a
57 [ -x /etc/rc.d/rc.acct ] && /etc/rc.d/rc.acct stop
59 if [ -x /sbin/quotaoff ]; then
60 run_cmd "Turning off quotas for local filesystems" /sbin/quotaoff -a
63 # Unmount file systems, killing processes if we have to.
67 remaining=$(awk '!/(^#| proc | loopfs | devpts | shm | iso9660 | ramfs | tmpfs | sysfs | securityfs | squashfs |^none|^\/dev\/root| \/ )/ {print $2}' /proc/mounts)
68 while [ -n "$remaining" -a "$retry" -gt 0 ]; do
69 show "Unmounting file systems"; busy
70 ERRORS=$(umount -a $force -t noproc 2>&1); rc=$?
72 # we might had unmounted /usr, recheck $TPUT availability
73 # but well. we need tput only for show() and busy() (ok() and fail() messages are already cached)
74 # TODO: look ahead the messages?
75 if is_yes "$TPUT"; then
84 [ -n "$ERRORS" ] && echo "$ERRORS"
88 remaining=$(awk '!/(^#| proc | loopfs | devpts | shm | iso9660 | ramfs | tmpfs | sysfs | securityfs | squashfs |^none|^\/dev\/root| \/ )/ {print $2}' /proc/mounts)
89 [ -z "$remaining" ] && break
90 fuser -k -m $sig $remaining > /dev/null
97 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
99 if is_yes "$EVMS_LVM" || [ -x /sbin/vgscan -a -x /sbin/vgchange ]; then
100 lvmversion=$(/sbin/vgchange --version 2>/dev/null | awk '{gsub("vgchange: Logical Volume Manager ",""); gsub("LVM version: ",""); gsub(/\..*/,"");print $1; exit}')
101 if [ "$lvmversion" = "2" ] ; then
102 lvmignorelock="--ignorelockingfailure"
106 run_cmd "Stopping LVM volume groups" /sbin/vgchange -a n $lvmignorelock
110 if [ -x /sbin/mdadm -a -f /etc/mdadm.conf ]; then
111 if (grep -qE "^([[:blank:]]|)ARRAY[[:blank:]]" /etc/mdadm.conf 2>/dev/null); then
112 /sbin/mdadm --stop --scan > /dev/null 2>&1
114 [ "$rc" -eq 0 ] && goraidtab=0
119 if [ -x /sbin/raidstop -a -f /etc/raidtab -a "$goraidtab" -eq 1 ]; then
120 # we can not use raidstop -a here because this will only stop
121 # devices listed in the default config file which is not always
122 # the case. So we look only for the active raid devices
123 if [ -f /proc/mdstat ] ; then
124 mddevs=$(awk '/^md.* active/ {print $1}' /proc/mdstat)
125 for mddev in $mddevs ; do
126 show "Turning off RAID for %s" "$mddev"
127 daemon /sbin/raidstop /dev/$mddev
131 # runcmd "Turning off RAID" /sbin/raidstop -a
134 show "Remounting remaining filesystems ro mode"; busy
135 if ( mount | awk '/ext2|ext3|reiserfs|xfs|jfs/ { print $3 }' | \
137 mount -n -o ro,remount $line; done ); then
144 _rebootwhat="vserver"
147 if [ -f /etc/crypttab ] && ! is_empty_file /etc/crypttab; then
148 . /etc/rc.d/init.d/cryptsetup
150 show "Stopping disk encryption"
151 halt_crypto && ok || fail
154 if [ "$runlevel" = "0" ] ; then
155 show "The $_rebootwhat is halted"; ok
156 [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok)
158 if [ -f /etc/killpower -a -f /etc/sysconfig/ups ] ; then
160 if is_yes "$POWEROFF_UPS"; then
161 if [ -d /etc/ups.d ]; then
162 for i in /etc/ups.d/*.sh; do
163 [ ! -f $i -o ! -x $i ] && continue
167 [ -x /sbin/poweroff-ups ] && /sbin/poweroff-ups
170 [ "$previous" != "unknown" ] && eval halt -d -p -f
172 show "Please stand by while rebooting the $_rebootwhat"; ok
173 [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok)
174 [ -x /sbin/kexec ] && /sbin/kexec -e
175 [ "$previous" != "unknown" ] && eval reboot -d -f