]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/rc.shutdown
- /etc/crypttab shouldn't be empty when using it
[projects/rc-scripts.git] / rc.d / rc.shutdown
1 #!/bin/sh
2 #
3 # shutdown      Common script for system halt/reboot.
4 #
5 # Author:       Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
6 #
7 # $Id$
8
9 # Set the path.
10 PATH=/sbin:/bin:/usr/bin:/usr/sbin
11
12 # move to root dir
13 cd /
14
15 IN_SHUTDOWN=yes
16
17 . /etc/rc.d/init.d/functions
18
19 # avoid keyboard interruption
20 trap "echo" INT SEGV QUIT TERM
21 set +e
22
23 rc_splash "reboot"
24
25 # Kill all processes.
26 [ "${BASH+bash}" = bash ] && enable kill
27
28 runlevel=$1
29 previous=$2
30
31 # Stop blogd before umounting /var
32 if [ -x /sbin/blogd ] && ! is_no "$RC_BOOTLOG"; then
33         killall -QUIT blogd
34 fi
35
36
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
43 fi
44
45 pids=$(pgrep -g 0 -l -v | grep -v '^1 ')
46 if [ -n "$pids" ]; then
47         sleep 5
48         run_cmd "Sending all processes the KILL signal" killall5 -9
49 fi
50
51 # Write to wtmp file before unmounting /var
52 halt -w
53
54 if ! is_yes "$VSERVER"; then
55         # Turn off swap, then unmount file systems.
56         run_cmd "Turning off swap" swapoff -a
57
58         [ -x /etc/rc.d/rc.acct ] && /etc/rc.d/rc.acct stop
59
60         if [ -x /sbin/quotaoff ]; then
61                 run_cmd "Turning off quotas for local filesystems" /sbin/quotaoff -a
62         fi
63
64         # Unmount file systems, killing processes if we have to.
65         sig=-15
66         retry=3
67         force=
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=$?
72
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
77                         TPUT=
78                         rc_gettext_init
79                 fi
80
81                 if [ $rc = 0 ]; then
82                         ok
83                 else
84                         fail
85                         [ -n "$ERRORS" ] && echo "$ERRORS"
86                 fi
87
88                 sleep 2
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
92                 sleep 5
93                 retry=$(($retry-1))
94                 sig=-9
95                 force="-f"
96         done
97
98         run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
99
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"
104                 else
105                         lvmignorelock=""
106                 fi
107                 run_cmd "Stopping LVM volume groups" /sbin/vgchange -a n $lvmignorelock
108         fi
109
110         goraidtab=1
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
114                         rc=$?
115                         [ "$rc" -eq 0 ] && goraidtab=0
116                 fi
117         fi
118
119         # turn off raid
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
129                         done
130                         unset mddev mddevs
131                 fi
132                 # runcmd "Turning off RAID" /sbin/raidstop -a
133         fi
134
135         show "Remounting remaining filesystems ro mode"; busy
136         if ( mount | awk '/ext2|ext3|reiserfs|xfs|jfs/ { print $3 }' | \
137                 while read line; do
138                 mount -n -o ro,remount $line; done ); then
139                 ok
140         else
141                 fail
142         fi
143         _rebootwhat="system"
144 else
145         _rebootwhat="vserver"
146 fi
147
148 if [ -f /etc/crypttab ] && ! is_empty_file /etc/crypttab; then
149         . /etc/rc.d/init.d/cryptsetup
150
151         show "Stopping disk encryption"
152         halt_crypto && ok || fail
153 fi
154
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)
158
159         if [ -x /sbin/poweroff-ups -a -f /etc/killpower -a -f /etc/sysconfig/ups ] ; then
160                 . /etc/sysconfig/ups
161                 is_yes "$POWEROFF_UPS" && /sbin/poweroff-ups
162         fi
163         [ "$previous" != "unknown" ] && eval halt -d -p
164 else
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
169 fi
170
171 # This must be last line !
172 # vi:syntax=sh
This page took 0.05033 seconds and 4 git commands to generate.