3 # shutdwn Common script for system halt/reboot.
5 # Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
6 # Changes: Grzegorz Stanislawski <stangrze@open.net.pl>
7 # Arkadiusz Mi¶kiewicz <misiek@pld-linux.org>
12 PATH=/sbin:/bin:/usr/bin:/usr/sbin
19 . /etc/rc.d/init.d/functions
21 # avoid keyboard interruption
22 trap "echo" INT SEGV QUIT TERM
28 [ "${BASH+bash}" = bash ] && enable kill
33 # check for other processes.
34 # there could be none if all services were terminated properly
35 # pgrep -g 0 requires procps >= 3.2.6-1.1
36 pids=$(pgrep -g 0 -l -v | grep -v '^1 ')
37 if [ -n "$pids" ]; then
38 run_cmd "Sending all processes the TERM signal" killall5 -15
41 pids=$(pgrep -g 0 -l -v | grep -v '^1 ')
42 if [ -n "$pids" ]; then
44 run_cmd "Sending all processes the KILL signal" killall5 -9
47 # Write to wtmp file before unmounting /var
50 if ! is_yes "$VSERVER"; then
51 # Turn off swap, then unmount file systems.
52 run_cmd "Turning off swap" swapoff -a
54 [ -x /etc/rc.d/rc.acct ] && /etc/rc.d/rc.acct stop
56 if [ -x /sbin/quotaoff ]; then
57 run_cmd "Turning off quotas for local filesystems" /sbin/quotaoff -a
60 # Unmount file systems, killing processes if we have to.
64 remaining=$(awk '!/(^#| proc | loopfs | devfs | devpts | shm | iso9660 | ramfs | tmpfs | sysfs | securityfs | squashfs |^none|^\/dev\/root| \/ )/ {print $2}' /proc/mounts)
65 while [ -n "$remaining" -a "$retry" -gt 0 ]; do
66 show "Unmounting file systems"; busy
67 ERRORS=$(umount -a $FORCE -t noproc,devfs 2>&1); rc=$?
69 # we might had unmounted /usr, recheck $TPUT availability
70 # but well. we need tput only for show() and busy() (ok() and fail() messages are already cached)
71 # TODO: look ahead the messages?
72 if is_yes "$TPUT"; then
81 [ -n "$ERRORS" ] && echo "$ERRORS"
85 remaining=$(awk '!/(^#| proc | loopfs | devfs | devpts | shm | iso9660 | ramfs | tmpfs | sysfs | securityfs | squashfs |^none|^\/dev\/root| \/ )/ {print $2}' /proc/mounts)
86 [ -z "$remaining" ] && break
87 /sbin/fuser -k -m $sig $remaining > /dev/null
94 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
96 if is_yes "$EVMS_LVM" || [ -x /sbin/vgscan -a -x /sbin/vgchange ]; then
97 lvmversion=$(/sbin/vgchange --version 2>/dev/null | awk '{gsub("vgchange: Logical Volume Manager ",""); gsub("LVM version: ",""); gsub(/\..*/,"");print $1; exit}')
98 if [ "$lvmversion" = "2" ] ; then
99 lvmignorelock="--ignorelockingfailure"
103 run_cmd "Stopping LVM volume groups" /sbin/vgchange -a n $lvmignorelock
107 if [ -x /sbin/mdadm -a -f /etc/mdadm.conf ]; then
108 if (grep -qE "^([[:blank:]]|)ARRAY[[:blank:]]" /etc/mdadm.conf 2>/dev/null); then
109 run_cmd "Turning off RAID devices" /sbin/mdadm --stop --scan
111 [ "$rc" -eq 0 ] && goraidtab=0
116 if [ -x /sbin/raidstop -a -f /etc/raidtab -a "$goraidtab" -eq 1 ]; then
117 # we can not use raidstop -a here because this will only stop
118 # devices listed in the default config file which is not always
119 # the case. So we look only for the active raid devices
120 if [ -f /proc/mdstat ] ; then
121 mddevs=$(awk '/^md.* active/ {print $1}' /proc/mdstat)
122 for mddev in $mddevs ; do
123 show "Turning off RAID for %s" "$mddev"
124 daemon /sbin/raidstop /dev/$mddev
128 # runcmd "Turning off RAID" /sbin/raidstop -a
131 show "Remounting remaining filesystems ro mode"; busy
132 if ( mount | awk '/ext2|ext3|reiserfs|xfs|jfs/ { print $3 }' | \
134 mount -n -o ro,remount $line; done ); then
141 _rebootwhat="vserver"
144 if [ "$runlevel" = "0" ] ; then
145 show "The $_rebootwhat is halted"; ok
146 [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok)
148 if [ -x /sbin/poweroff-ups -a -f /etc/killpower -a -f /etc/sysconfig/ups ] ; then
150 is_yes "$POWEROFF_UPS" && /sbin/poweroff-ups
152 [ "$previous" != "unknown" ] && eval halt -d -p
154 show "Please stand by while rebooting the $_rebootwhat"; ok
155 [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok)
156 [ -x /sbin/kexec ] && /sbin/kexec -e
157 [ "$previous" != "unknown" ] && eval reboot -d
160 # This must be last line !