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