]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/rc.shutdown
Sync remaining variable in fs umounting. Add squashfs there.
[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 . /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
30 run_cmd "Sending all processes the TERM signal" killall5 -15
31 sleep 5
32 run_cmd "Sending all processes the KILL signal" killall5 -9
33
34 # Write to wtmp file before unmounting /var
35 halt -w
36
37 # Turn off swap, then unmount file systems.
38 run_cmd "Turning off swap" swapoff -a
39
40 [ -x /etc/rc.d/rc.acct ] && /etc/rc.d/rc.acct stop
41
42 if [ -x /sbin/quotaoff ]; then
43         run_cmd "Turning off quotas for local filesystems" /sbin/quotaoff -a
44 fi
45
46 # Unmount file systems, killing processes if we have to.
47 sig=-15
48 retry=3
49 force=
50 remaining=$(awk '!/(^#| proc | loopfs | devfs | devpts | shm | iso9660 | ramfs | tmpfs | sysfs | squashfs |^none|^\/dev\/root| \/ )/ {print $2}' /proc/mounts)
51 while [ -n "$remaining" -a "$retry" -gt 0 ]
52 do      
53         show "Unmounting file systems" ; busy
54         if ERRORS=$(umount -a $FORCE -t noproc,devfs 2>&1) ; then
55                 ok
56         else
57                 fail
58                 [ -n "$ERRORS" ] && echo "$ERRORS"
59         fi
60         
61         sleep 2
62         remaining=$(awk '!/(^#| proc | loopfs | devfs | devpts | shm | iso9660 | ramfs | tmpfs | sysfs | squashfs |^none|^\/dev\/root| \/ )/ {print $2}' /proc/mounts)
63         [ -z "$remaining" ] && break
64         /sbin/fuser -k -m $sig $remaining > /dev/null
65         sleep 5
66         retry=$(($retry-1))
67         sig=-9
68         force="-f"
69 done
70
71 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
72
73 # turn off raid
74 if [ -x /sbin/raidstop -a -f /etc/raidtab ]; then
75         # we can not use raidstop -a here because this will only stop
76         # devices listed in the default config file which is not always
77         # the case. So we look only for the active raid devices
78         if [ -f /proc/mdstat ] ; then
79                 mddevs=$(awk '/^md.* active/ {print $1}' /proc/mdstat)
80                 for mddev in $mddevs ; do
81                         run_cmd "Turning off RAID for $mddev" raidstop /dev/$mddev
82                 done
83                 unset mddev mddevs
84         fi
85         #runcmd "Turning off RAID" /sbin/raidstop -a
86 fi
87
88 show "Remounting remaining filesystems ro mode"; busy
89 if ( mount | awk '/ext2|ext3|reiserfs|xfs|jfs/ { print $3 }' | \
90         while read line; do 
91         mount -n -o ro,remount $line; done ); then
92         ok
93 else
94         fail
95 fi
96
97 if [ "$runlevel" = "0" ] ; then
98         show "The system is halted"; ok
99         [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok)
100
101          if [ -x /sbin/poweroff-ups -a -f /etc/killpower -a -f /etc/sysconfig/ups ] ; then
102              . /etc/sysconfig/ups
103              is_yes "$POWEROFF_UPS" && /sbin/poweroff-ups
104          fi
105         eval halt -d -p
106 else
107         show "Please stand by while rebooting the system"; ok
108         [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok)
109         [ -x /sbin/kexec ] && /sbin/kexec -e
110         eval reboot -d
111 fi
112
113 # This must be last line !
114 # vi:syntax=sh:tw=78:ts=8:sw=4
This page took 0.063673 seconds and 4 git commands to generate.