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 ]
67 show "Unmounting file systems" ; busy
68 if ERRORS=$(umount -a $FORCE -t noproc,devfs 2>&1) ; then
72 [ -n "$ERRORS" ] && echo "$ERRORS"
76 remaining=$(awk '!/(^#| proc | loopfs | devfs | devpts | shm | iso9660 | ramfs | tmpfs | sysfs | securityfs | squashfs |^none|^\/dev\/root| \/ )/ {print $2}' /proc/mounts)
77 [ -z "$remaining" ] && break
78 /sbin/fuser -k -m $sig $remaining > /dev/null
85 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
87 if is_yes "$EVMS_LVM" || [ -x /sbin/vgscan -a -x /sbin/vgchange ]; then
88 lvmversion=$(/sbin/vgchange --version 2>/dev/null | awk '{gsub("vgchange: Logical Volume Manager ",""); gsub("LVM version: ",""); gsub(/\..*/,"");print $1; exit}')
89 if [ "$lvmversion" = "2" ] ; then
90 lvmignorelock="--ignorelockingfailure"
94 run_cmd "Stopping LVM volume groups" /sbin/vgchange -a n $lvmignorelock
98 if [ -x /sbin/mdadm -a -f /etc/mdadm.conf ]; then
99 if (grep -qE "^([[:blank:]]|)ARRAY[[:blank:]]" /etc/mdadm.conf 2>/dev/null); then
100 run_cmd "Turning off RAID devices" /sbin/mdadm --stop --scan
102 [ "$rc" -eq 0 ] && goraidtab=0
107 if [ -x /sbin/raidstop -a -f /etc/raidtab -a "$goraidtab" -eq 1 ]; then
108 # we can not use raidstop -a here because this will only stop
109 # devices listed in the default config file which is not always
110 # the case. So we look only for the active raid devices
111 if [ -f /proc/mdstat ] ; then
112 mddevs=$(awk '/^md.* active/ {print $1}' /proc/mdstat)
113 for mddev in $mddevs ; do
114 show "Turning off RAID for %s" "$mddev"
115 daemon /sbin/raidstop /dev/$mddev
119 # runcmd "Turning off RAID" /sbin/raidstop -a
122 show "Remounting remaining filesystems ro mode"; busy
123 if ( mount | awk '/ext2|ext3|reiserfs|xfs|jfs/ { print $3 }' | \
125 mount -n -o ro,remount $line; done ); then
132 _rebootwhat="vserver"
135 if [ "$runlevel" = "0" ] ; then
136 show "The $_rebootwhat is halted"; ok
137 [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok)
139 if [ -x /sbin/poweroff-ups -a -f /etc/killpower -a -f /etc/sysconfig/ups ] ; then
141 is_yes "$POWEROFF_UPS" && /sbin/poweroff-ups
143 [ "$previous" != "unknown" ] && eval halt -d -p
145 show "Please stand by while rebooting the $_rebootwhat"; ok
146 [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok)
147 [ -x /sbin/kexec ] && /sbin/kexec -e
148 [ "$previous" != "unknown" ] && eval reboot -d
151 # This must be last line !