]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/rc.shutdown
merged totalnew 3d patch as new TOTALNEW branch
[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.org.pl>
8 #
9 # $Id: rc.shutdown,v 1.12.2.1 2000/10/18 20:10:49 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 ] && LC_ALL=C /sbin/accton 2>&1 | grep -v "not implemented"
35
36 if [ -x /sbin/quotaoff ]; then
37         run_cmd "Turning off quotas for local filesystems" /sbin/quotaoff -a
38 fi
39
40 # Unmount file systems, killing processes if we have to.
41 sig=-15
42 retry=3
43 force=
44 remaining=$(awk '!/(^#| proc | loopfs | devfs | devpts | shm |^none|^\/dev\/root| \/ )/ {print $2}' /proc/mounts)
45 while [ -n "$remaining" -a "$retry" -gt 0 ]
46 do      
47         show "Unmounting file systems" ; busy
48         if ERRORS=$(LC_ALL=C exec umount -a $FORCE -t noproc 2>&1) ; then
49                 ok
50         else
51                 fail
52                 [ -n "$ERRORS" ] && echo "$ERRORS"
53         fi
54         
55         sleep 2
56         remaining=$(awk '!/(^#| proc | loopfs | devfs | devpts | shm |^none|^\/dev\/root| \/ )/ {print $2}' /proc/mounts)
57         [ -z "$remaining" ] && break
58         /sbin/fuser -k -m $sig $remaining > /dev/null
59         sleep 5
60         retry=$(($retry-1))
61         sig=-9
62         force="-f"
63 done
64
65 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
66
67 # turn off raid
68 if [ -x /sbin/raidstop -a -f /etc/raidtab ]; then
69         # we can not use raidstop -a here because this will only stop
70         # devices listed in the default config file which is not always
71         # the case. So we look only for the active raid devices
72         if [ -f /proc/mdstat ] ; then
73                 mddevs=$(awk '/^md.* active/ {print $1}' /proc/mdstat)
74                 for mddev in $mddevs ; do
75                         MESSAGE="$(nls "Turning off RAID for %s" "$mddev")"
76                         run_cmd "$MESSAGE" raidstop /dev/$mddev
77                 done
78                 unset mddev mddevs
79         fi
80         #runcmd "Turning off RAID" /sbin/raidstop -a
81 fi
82
83 show "Remounting remaining filesystems ro mode"; busy
84 if ( mount | awk '/ext2|ext3|reiserfs/ { print $3 }' | \
85         while read line; do 
86         mount -n -o ro,remount $line; done ); then
87         ok
88 else
89         fail
90 fi
91
92 # This must be last line !
93 # vi:syntax=sh:tw=78:ts=8:sw=4
94
This page took 0.037275 seconds and 4 git commands to generate.