]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/rc.shutdown
- change reboot/halt message for vserver (request by glen)
[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 run_cmd "Sending all processes the TERM signal" killall5 -15
34 sleep 5
35 run_cmd "Sending all processes the KILL signal" killall5 -9
36
37 # Write to wtmp file before unmounting /var
38 halt -w
39
40 # Turn off swap, then unmount file systems.
41 run_cmd "Turning off swap" swapoff -a
42
43 [ -x /etc/rc.d/rc.acct ] && /etc/rc.d/rc.acct stop
44
45 if [ -x /sbin/quotaoff ]; then
46         run_cmd "Turning off quotas for local filesystems" /sbin/quotaoff -a
47 fi
48
49 if ! is_yes "$VSERVER"; then
50         # Unmount file systems, killing processes if we have to.
51         sig=-15
52         retry=3
53         force=
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 ]
56         do
57                 show "Unmounting file systems" ; busy
58                 if ERRORS=$(umount -a $FORCE -t noproc,devfs 2>&1) ; then
59                         ok
60                 else
61                         fail
62                         [ -n "$ERRORS" ] && echo "$ERRORS"
63                 fi
64
65                 sleep 2
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
69                 sleep 5
70                 retry=$(($retry-1))
71                 sig=-9
72                 force="-f"
73         done
74
75         run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
76
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"
81                 else
82                         lvmignorelock=""
83                 fi
84                 run_cmd "Stopping LVM volume groups" /sbin/vgchange -a n $lvmignorelock
85         fi
86
87         goraidtab=1
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
91                         rc=$?
92                         [ "$rc" -eq 0 ] && goraidtab=0
93                 fi
94         fi
95
96         # turn off raid
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
106                         done
107                         unset mddev mddevs
108                 fi
109                 # runcmd "Turning off RAID" /sbin/raidstop -a
110         fi
111
112         show "Remounting remaining filesystems ro mode"; busy
113         if ( mount | awk '/ext2|ext3|reiserfs|xfs|jfs/ { print $3 }' | \
114                 while read line; do
115                 mount -n -o ro,remount $line; done ); then
116                 ok
117         else
118                 fail
119         fi
120 fi
121
122 if ! is_yes "$VSERVER"; then
123         _rebootwhat="system"
124 else
125         _rebootwhat="vserver"
126 fi
127
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)
131
132         if [ -x /sbin/poweroff-ups -a -f /etc/killpower -a -f /etc/sysconfig/ups ] ; then
133                 . /etc/sysconfig/ups
134                 is_yes "$POWEROFF_UPS" && /sbin/poweroff-ups
135         fi
136         [ "$previous" != "unknown" ] && eval halt -d -p
137 else
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
142 fi
143
144 # This must be last line !
145 # vi:syntax=sh
This page took 0.179857 seconds and 4 git commands to generate.