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 run_cmd "Sending all processes the TERM signal" killall5 -15
35 run_cmd "Sending all processes the KILL signal" killall5 -9
37 # Write to wtmp file before unmounting /var
40 # Turn off swap, then unmount file systems.
41 run_cmd "Turning off swap" swapoff -a
43 [ -x /etc/rc.d/rc.acct ] && /etc/rc.d/rc.acct stop
45 if [ -x /sbin/quotaoff ]; then
46 run_cmd "Turning off quotas for local filesystems" /sbin/quotaoff -a
49 if ! is_yes "$VSERVER"; then
50 # Unmount file systems, killing processes if we have to.
54 remaining=$(awk '!/(^#| proc | loopfs | devfs | devpts | shm | iso9660 | ramfs | tmpfs | sysfs | securityfs | squashfs |^none|^\/dev\/root| \/ )/ {print $2}' /proc/mounts)
55 while [ -n "$remaining" -a "$retry" -gt 0 ]
57 show "Unmounting file systems" ; busy
58 if ERRORS=$(umount -a $FORCE -t noproc,devfs 2>&1) ; then
62 [ -n "$ERRORS" ] && echo "$ERRORS"
66 remaining=$(awk '!/(^#| proc | loopfs | devfs | devpts | shm | iso9660 | ramfs | tmpfs | sysfs | securityfs | squashfs |^none|^\/dev\/root| \/ )/ {print $2}' /proc/mounts)
67 [ -z "$remaining" ] && break
68 /sbin/fuser -k -m $sig $remaining > /dev/null
75 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
77 if is_yes "$EVMS_LVM" || [ -x /sbin/vgscan -a -x /sbin/vgchange ]; then
78 lvmversion=$(/sbin/vgchange --version 2>/dev/null | awk '{gsub("vgchange: Logical Volume Manager ",""); gsub("LVM version: ",""); gsub(/\..*/,"");print $1; exit}')
79 if [ "$lvmversion" = "2" ] ; then
80 lvmignorelock="--ignorelockingfailure"
84 run_cmd "Stopping LVM volume groups" /sbin/vgchange -a n $lvmignorelock
88 if [ -x /sbin/mdadm -a -f /etc/mdadm.conf ]; then
89 if (grep -qE "^([[:blank:]]|)ARRAY[[:blank:]]" /etc/mdadm.conf 2>/dev/null); then
90 run_cmd "Turning off RAID devices" /sbin/mdadm --stop --scan
92 [ "$rc" -eq 0 ] && goraidtab=0
97 if [ -x /sbin/raidstop -a -f /etc/raidtab -a "$goraidtab" -eq 1 ]; then
98 # we can not use raidstop -a here because this will only stop
99 # devices listed in the default config file which is not always
100 # the case. So we look only for the active raid devices
101 if [ -f /proc/mdstat ] ; then
102 mddevs=$(awk '/^md.* active/ {print $1}' /proc/mdstat)
103 for mddev in $mddevs ; do
104 show "Turning off RAID for %s" "$mddev"
105 daemon /sbin/raidstop /dev/$mddev
109 # runcmd "Turning off RAID" /sbin/raidstop -a
112 show "Remounting remaining filesystems ro mode"; busy
113 if ( mount | awk '/ext2|ext3|reiserfs|xfs|jfs/ { print $3 }' | \
115 mount -n -o ro,remount $line; done ); then
122 if ! is_yes "$VSERVER"; then
125 _rebootwhat="vserver"
128 if [ "$runlevel" = "0" ] ; then
129 show "The $_rebootwhat is halted"; ok
130 [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok)
132 if [ -x /sbin/poweroff-ups -a -f /etc/killpower -a -f /etc/sysconfig/ups ] ; then
134 is_yes "$POWEROFF_UPS" && /sbin/poweroff-ups
136 [ "$previous" != "unknown" ] && eval halt -d -p
138 show "Please stand by while rebooting the $_rebootwhat"; ok
139 [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok)
140 [ -x /sbin/kexec ] && /sbin/kexec -e
141 [ "$previous" != "unknown" ] && eval reboot -d
144 # This must be last line !