]> git.pld-linux.org Git - projects/rc-scripts.git/blame - rc.d/rc.shutdown
- refactor awk invocation in fs unmounting code
[projects/rc-scripts.git] / rc.d / rc.shutdown
CommitLineData
791f7cd2
JR
1#!/bin/sh
2#
af55fe6b 3# shutdown Common script for system halt/reboot.
791f7cd2 4#
5e6dfc29 5# Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
791f7cd2 6#
ec8b15cb 7# $Id$
791f7cd2
JR
8
9# Set the path.
10PATH=/sbin:/bin:/usr/bin:/usr/sbin
11
de160ea3
AM
12# move to root dir
13cd /
14
d84e0c78
JR
15IN_SHUTDOWN=yes
16
791f7cd2
JR
17. /etc/rc.d/init.d/functions
18
b6509675
AM
19# avoid keyboard interruption
20trap "echo" INT SEGV QUIT TERM
21set +e
22
23rc_splash "reboot"
24
791f7cd2
JR
25# Kill all processes.
26[ "${BASH+bash}" = bash ] && enable kill
27
d0f42664 28runlevel=$1
cc10e704 29previous=$2
d0f42664 30
0868c9a6 31# Stop blogd before umounting /var
b171122f
ER
32if [ -x /sbin/blogd ]; then
33 killall -q -QUIT blogd
0868c9a6
ER
34fi
35
74c57003
AM
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
39pids=$(pgrep -g 0 -l -v | grep -v '^1 ')
40if [ -n "$pids" ]; then
41 run_cmd "Sending all processes the TERM signal" killall5 -15
42fi
43
44pids=$(pgrep -g 0 -l -v | grep -v '^1 ')
45if [ -n "$pids" ]; then
46 sleep 5
47 run_cmd "Sending all processes the KILL signal" killall5 -9
48fi
791f7cd2
JR
49
50# Write to wtmp file before unmounting /var
1822a5a6 51halt -w
791f7cd2 52
1aaf8c92
JR
53if ! is_yes "$VSERVER"; then
54 # Turn off swap, then unmount file systems.
55 run_cmd "Turning off swap" swapoff -a
7d7fd6c1 56
1aaf8c92 57 [ -x /etc/rc.d/rc.acct ] && /etc/rc.d/rc.acct stop
791f7cd2 58
1aaf8c92
JR
59 if [ -x /sbin/quotaoff ]; then
60 run_cmd "Turning off quotas for local filesystems" /sbin/quotaoff -a
61 fi
2eec3807 62
cc10e704
JR
63 # Unmount file systems, killing processes if we have to.
64 sig=-15
65 retry=3
66 force=
2850ca3d
JR
67 remaining=$(awk '$3 !~ /^(proc|loopfs|devpts|shm|iso9660|ramfs|tmpfs|sysfs|securityfs|squashfs)$/ \
68 && $1 !~ /^(none|\/dev\/root)$/ \
69 && $2 !~ /^\/$/ {print $2}' /proc/mounts)
2a57d1ce
ER
70 while [ -n "$remaining" -a "$retry" -gt 0 ]; do
71 show "Unmounting file systems"; busy
34c624e7 72 ERRORS=$(umount -a $force -t noproc 2>&1); rc=$?
2a57d1ce
ER
73
74 # we might had unmounted /usr, recheck $TPUT availability
75 # but well. we need tput only for show() and busy() (ok() and fail() messages are already cached)
76 # TODO: look ahead the messages?
77 if is_yes "$TPUT"; then
78 TPUT=
79 rc_gettext_init
80 fi
81
82 if [ $rc = 0 ]; then
cc10e704
JR
83 ok
84 else
85 fail
86 [ -n "$ERRORS" ] && echo "$ERRORS"
87 fi
5e6dfc29 88
cc10e704 89 sleep 2
2850ca3d
JR
90 remaining=$(awk '$3 !~ /^(proc|loopfs|devpts|shm|iso9660|ramfs|tmpfs|sysfs|securityfs|squashfs)$/ \
91 && $1 !~ /^(none|\/dev\/root)$/ \
92 && $2 !~ /^\/$/ {print $2}' /proc/mounts)
cc10e704 93 [ -z "$remaining" ] && break
4b0d64e2 94 fuser -k -m $sig $remaining > /dev/null
cc10e704
JR
95 sleep 5
96 retry=$(($retry-1))
97 sig=-9
98 force="-f"
99 done
100
101 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
102
103 if is_yes "$EVMS_LVM" || [ -x /sbin/vgscan -a -x /sbin/vgchange ]; then
104 lvmversion=$(/sbin/vgchange --version 2>/dev/null | awk '{gsub("vgchange: Logical Volume Manager ",""); gsub("LVM version: ",""); gsub(/\..*/,"");print $1; exit}')
105 if [ "$lvmversion" = "2" ] ; then
106 lvmignorelock="--ignorelockingfailure"
107 else
108 lvmignorelock=""
109 fi
110 run_cmd "Stopping LVM volume groups" /sbin/vgchange -a n $lvmignorelock
41781ded 111 fi
41781ded 112
cc10e704
JR
113 goraidtab=1
114 if [ -x /sbin/mdadm -a -f /etc/mdadm.conf ]; then
115 if (grep -qE "^([[:blank:]]|)ARRAY[[:blank:]]" /etc/mdadm.conf 2>/dev/null); then
9045fdf6 116 /sbin/mdadm --stop --scan > /dev/null 2>&1
5e6dfc29
JR
117 rc=$?
118 [ "$rc" -eq 0 ] && goraidtab=0
cc10e704 119 fi
8fb3abd8 120 fi
5e6dfc29 121
cc10e704
JR
122 # turn off raid
123 if [ -x /sbin/raidstop -a -f /etc/raidtab -a "$goraidtab" -eq 1 ]; then
124 # we can not use raidstop -a here because this will only stop
125 # devices listed in the default config file which is not always
126 # the case. So we look only for the active raid devices
127 if [ -f /proc/mdstat ] ; then
128 mddevs=$(awk '/^md.* active/ {print $1}' /proc/mdstat)
129 for mddev in $mddevs ; do
130 show "Turning off RAID for %s" "$mddev"
131 daemon /sbin/raidstop /dev/$mddev
132 done
133 unset mddev mddevs
134 fi
135 # runcmd "Turning off RAID" /sbin/raidstop -a
791f7cd2 136 fi
791f7cd2 137
cc10e704
JR
138 show "Remounting remaining filesystems ro mode"; busy
139 if ( mount | awk '/ext2|ext3|reiserfs|xfs|jfs/ { print $3 }' | \
5e6dfc29 140 while read line; do
cc10e704
JR
141 mount -n -o ro,remount $line; done ); then
142 ok
143 else
144 fail
145 fi
2e33f3ce
JR
146 _rebootwhat="system"
147else
148 _rebootwhat="vserver"
149fi
150
6b496866 151if [ -f /etc/crypttab ] && ! is_empty_file /etc/crypttab; then
8710c4b5
ER
152 . /etc/rc.d/init.d/cryptsetup
153
154 show "Stopping disk encryption"
878e1414
ER
155 halt_crypto && ok || fail
156fi
157
d0f42664 158if [ "$runlevel" = "0" ] ; then
2e33f3ce 159 show "The $_rebootwhat is halted"; ok
d0f42664 160 [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok)
bc451b91 161
d0b6372d 162 if [ -f /etc/killpower -a -f /etc/sysconfig/ups ] ; then
5e6dfc29 163 . /etc/sysconfig/ups
d0b6372d
AM
164 if is_yes "$POWEROFF_UPS"; then
165 if [ -d /etc/ups.d ]; then
03ef5439 166 for i in /etc/ups.d/*.sh; do
d0b6372d
AM
167 [ ! -f $i -o ! -x $i ] && continue
168 $i poweroff
169 done
170 fi
171 [ -x /sbin/poweroff-ups ] && /sbin/poweroff-ups
172 fi
cc10e704 173 fi
b1087329 174 [ "$previous" != "unknown" ] && eval halt -d -p -f
d0f42664 175else
2e33f3ce 176 show "Please stand by while rebooting the $_rebootwhat"; ok
d0f42664 177 [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok)
6dde00e1 178 [ -x /sbin/kexec ] && /sbin/kexec -e
b1087329 179 [ "$previous" != "unknown" ] && eval reboot -d -f
d0f42664 180fi
This page took 0.31469 seconds and 4 git commands to generate.