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 ] && ! is_no "$RC_BOOTLOG"; then
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
45 pids=$(pgrep -g 0 -l -v | grep -v '^1 ')
46 if [ -n "$pids" ]; then
48 run_cmd "Sending all processes the KILL signal" killall5 -9
51 # Write to wtmp file before unmounting /var
54 if ! is_yes "$VSERVER"; then
55 # Turn off swap, then unmount file systems.
56 run_cmd "Turning off swap" swapoff -a
58 [ -x /etc/rc.d/rc.acct ] && /etc/rc.d/rc.acct stop
60 if [ -x /sbin/quotaoff ]; then
61 run_cmd "Turning off quotas for local filesystems" /sbin/quotaoff -a
64 # Unmount file systems, killing processes if we have to.
68 remaining=$(awk '!/(^#| proc | loopfs | devfs | devpts | shm | iso9660 | ramfs | tmpfs | sysfs | securityfs | squashfs |^none|^\/dev\/root| \/ )/ {print $2}' /proc/mounts)
69 while [ -n "$remaining" -a "$retry" -gt 0 ]; do
70 show "Unmounting file systems"; busy
71 ERRORS=$(umount -a $force -t noproc,devfs 2>&1); rc=$?
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
85 [ -n "$ERRORS" ] && echo "$ERRORS"
89 remaining=$(awk '!/(^#| proc | loopfs | devfs | devpts | shm | iso9660 | ramfs | tmpfs | sysfs | securityfs | squashfs |^none|^\/dev\/root| \/ )/ {print $2}' /proc/mounts)
90 [ -z "$remaining" ] && break
91 /sbin/fuser -k -m $sig $remaining > /dev/null
98 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
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"
107 run_cmd "Stopping LVM volume groups" /sbin/vgchange -a n $lvmignorelock
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
113 run_cmd "Turning off RAID devices" /sbin/mdadm --stop --scan
115 [ "$rc" -eq 0 ] && goraidtab=0
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
132 # runcmd "Turning off RAID" /sbin/raidstop -a
135 show "Remounting remaining filesystems ro mode"; busy
136 if ( mount | awk '/ext2|ext3|reiserfs|xfs|jfs/ { print $3 }' | \
138 mount -n -o ro,remount $line; done ); then
145 _rebootwhat="vserver"
148 if [ -f /etc/crypttab ] && ! is_empty_file /etc/crypttab; then
149 . /etc/rc.d/init.d/cryptsetup
151 show "Stopping disk encryption"
152 halt_crypto && ok || fail
155 if [ "$runlevel" = "0" ] ; then
156 show "The $_rebootwhat is halted"; ok
157 [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok)
159 if [ -x /sbin/poweroff-ups -a -f /etc/killpower -a -f /etc/sysconfig/ups ] ; then
161 is_yes "$POWEROFF_UPS" && /sbin/poweroff-ups
163 [ "$previous" != "unknown" ] && eval halt -d -p
165 show "Please stand by while rebooting the $_rebootwhat"; ok
166 [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok)
167 [ -x /sbin/kexec ] && /sbin/kexec -e
168 [ "$previous" != "unknown" ] && eval reboot -d
171 # This must be last line !