]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/rc.shutdown
- new (better) unmounting procedure from initscripts
[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 #               Modified for PLD Linux by Grzegorz Stanislawski
7 # Changes:      Arkadiusz Mi¶kiewicz <misiek@pld.org.pl>
8 #
9 # $Id: rc.shutdown,v 1.2 2000/02/03 11:48:30 misiek Exp $
10
11 # Set the path.
12 PATH=/sbin:/bin:/usr/bin:/usr/sbin
13
14 # NLS
15 NLS_DOMAIN="rc-scripts"
16
17 # move to root dir
18 cd /
19
20 . /etc/rc.d/init.d/functions
21
22 # Kill all processes.
23 [ "${BASH+bash}" = bash ] && enable kill
24
25 run_cmd "Sending all processes the TERM signal" killall5 -15
26 sleep 5
27 run_cmd "Sending all processes the KILL signal" killall5 -9
28
29 # Write to wtmp file before unmounting /var
30 halt -w
31
32 # Turn off swap, then unmount file systems.
33 run_cmd "Turning off swap and accounting" swapoff -a
34 [ -x /sbin/accton ] && /sbin/accton
35
36 # Unmount file systems, killing processes if we have to.
37 sig=
38 retry=3
39 remaining=`awk '!/(^#|proc|^none|^\/dev\/root)/ {print $2}' /proc/mounts`
40 while [ -n "$remaining" -a "$retry" -gt 0 ]
41 do
42         run_cmd "Unmounting file systems"  umount -a -f -t noproc
43         sleep 2
44         remaining=`awk '!/(^#|proc|^none|^\/dev\/root)/ {print $2}' /proc/mounts`
45         [ -z "$remaining" ] && break
46         [ -x /sbin/fuser ] && /sbin/fuser -k -m $sig $remaining >/dev/null
47         sleep 5
48         retry=$(($retry-1))
49         sig=-9
50 done
51
52 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
53
54 # turn off raid
55 if [ -x /sbin/raidstop -a -f /etc/raidtab ]; then
56         # we can not use raidstop -a here because this will only stop
57         # devices listed in the default config file which is not always
58         # the case. So we look only for the active raid devices
59         if [ -f /proc/mdstat ] ; then
60                 mddevs=$(awk '/^md.* active/ {print $1}' /proc/mdstat)
61                 for mddev in $mddevs ; do
62                         MESSAGE="`nls "Turning off RAID for %s" "$mddev"`"
63                         run_cmd "$MESSAGE" raidstop /dev/$mddev
64                 done
65                 unset mddev mddevs
66         fi
67         #runcmd "Turning off RAID" /sbin/raidstop -a
68 fi
69
70 show "Remounting remaining filesystems ro mode"; busy
71 if ( mount | awk '/ext2/ { print $3 }' | \
72         while read line; do 
73         mount -n -o ro,remount $line; done ); then
74         deltext; ok
75 else
76         deltext; fail
77 fi
This page took 0.034968 seconds and 4 git commands to generate.