]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/rc.shutdown
Fixes for /usr on separate parition (not tested!).
[projects/rc-scripts.git] / rc.d / rc.shutdown
1 #!/bin/sh
2 #
3 # shutdwn       Common script for system halt/reboot.
4 #
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>
8 #
9 # $Id$
10
11 # Set the path.
12 PATH=/sbin:/bin:/usr/bin:/usr/sbin
13
14 # move to root dir
15 cd /
16
17 IN_SHUTDOWN=yes
18
19 . /etc/rc.d/init.d/functions
20
21 # avoid keyboard interruption
22 trap "echo" INT SEGV QUIT TERM
23 set +e
24
25 rc_splash "reboot"
26
27 # Kill all processes.
28 [ "${BASH+bash}" = bash ] && enable kill
29
30 runlevel=$1
31 previous=$2
32
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
39 fi
40
41 pids=$(pgrep -g 0 -l -v | grep -v '^1 ')
42 if [ -n "$pids" ]; then
43         sleep 5
44         run_cmd "Sending all processes the KILL signal" killall5 -9
45 fi
46
47 # Write to wtmp file before unmounting /var
48 halt -w
49
50 if ! is_yes "$VSERVER"; then
51         # Turn off swap, then unmount file systems.
52         run_cmd "Turning off swap" swapoff -a
53
54         [ -x /etc/rc.d/rc.acct ] && /etc/rc.d/rc.acct stop
55
56         if [ -x /sbin/quotaoff ]; then
57                 run_cmd "Turning off quotas for local filesystems" /sbin/quotaoff -a
58         fi
59
60         # Unmount file systems, killing processes if we have to.
61         sig=-15
62         retry=3
63         force=
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=$?
68
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
73                         TPUT=
74                         rc_gettext_init
75                 fi
76
77                 if [ $rc = 0 ]; then
78                         ok
79                 else
80                         fail
81                         [ -n "$ERRORS" ] && echo "$ERRORS"
82                 fi
83
84                 sleep 2
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
88                 sleep 5
89                 retry=$(($retry-1))
90                 sig=-9
91                 force="-f"
92         done
93
94         run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
95
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"
100                 else
101                         lvmignorelock=""
102                 fi
103                 run_cmd "Stopping LVM volume groups" /sbin/vgchange -a n $lvmignorelock
104         fi
105
106         goraidtab=1
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
110                         rc=$?
111                         [ "$rc" -eq 0 ] && goraidtab=0
112                 fi
113         fi
114
115         # turn off raid
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
125                         done
126                         unset mddev mddevs
127                 fi
128                 # runcmd "Turning off RAID" /sbin/raidstop -a
129         fi
130
131         show "Remounting remaining filesystems ro mode"; busy
132         if ( mount | awk '/ext2|ext3|reiserfs|xfs|jfs/ { print $3 }' | \
133                 while read line; do
134                 mount -n -o ro,remount $line; done ); then
135                 ok
136         else
137                 fail
138         fi
139         _rebootwhat="system"
140 else
141         _rebootwhat="vserver"
142 fi
143
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)
147
148         if [ -x /sbin/poweroff-ups -a -f /etc/killpower -a -f /etc/sysconfig/ups ] ; then
149                 . /etc/sysconfig/ups
150                 is_yes "$POWEROFF_UPS" && /sbin/poweroff-ups
151         fi
152         [ "$previous" != "unknown" ] && eval halt -d -p
153 else
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
158 fi
159
160 # This must be last line !
161 # vi:syntax=sh
This page took 0.626047 seconds and 4 git commands to generate.