/[baselayout]/trunk/init.d/halt.sh
Gentoo

Contents of /trunk/init.d/halt.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 214 - (show annotations) (download) (as text)
Sun Aug 4 03:10:10 2002 UTC (16 years, 8 months ago) by woodchip
File MIME type: text/x-sh
File size: 3497 byte(s)
added support for UPS shutdown

1 # Copyright 1999-2002 Gentoo Technologies, Inc.
2 # Distributed under the terms of the GNU General Public License, v2 or later
3 # $Header$
4
5
6 #we try to deactivate swap first because it seems to need devfsd running
7 #to work. The TERM and KILL stuff will zap devfsd, so...
8
9 ebegin "Deactivating swap"
10 swapoff -a &>/dev/null
11 eend $?
12
13 #we need to properly terminate devfsd to save the permissions
14 if [ "$(ps -A |grep devfsd)" ]
15 then
16 ebegin "Stopping devfsd"
17 killall -15 devfsd &>/dev/null
18 eend $?
19 fi
20
21 ebegin "Sending all processes the TERM signal"
22 killall5 -15 &>/dev/null
23 eend $?
24 sleep 5
25 ebegin "Sending all processes the KILL signal"
26 killall5 -9 &>/dev/null
27 eend $?
28
29 # Write a reboot record to /var/log/wtmp before unmounting
30
31 halt -w &>/dev/null
32
33 #unmounting should use /proc/mounts and work with/without devfsd running
34
35 # Credits for next function to unmount loop devices, goes to:
36 #
37 # Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
38 # Modified for RHS Linux by Damien Neil
39 #
40 #
41 # Unmount file systems, killing processes if we have to.
42 # Unmount loopback stuff first
43 remaining="$(awk '!/^#/ && $1 ~ /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts |sort -r)"
44 [ -n "${remaining}" ] && {
45 sig=
46 retry=3
47 while [ -n "${remaining}" -a "${retry}" -gt 0 ]
48 do
49 if [ "${retry}" -lt 3 ]
50 then
51 ebegin "Unmounting loopback filesystems (retry)"
52 umount ${remaining} &>/dev/null
53 eend $? "Failed to unmount filesystems this retry"
54 else
55 ebegin "Unmounting loopback filesystems"
56 umount ${remaining} &>/dev/null
57 eend $? "Failed to unmount filesystems"
58 fi
59 for dev in ${remaining}
60 do
61 losetup ${dev} &>/dev/null && {
62 ebegin " Detaching loopback device ${dev}"
63 /sbin/losetup -d ${dev} &>/dev/null
64 eend $? "Failed to detach device ${dev}"
65 }
66 done
67 remaining="$(awk '!/^#/ && $1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts |sort -r)"
68 [ -z "${remaining}" ] && break
69 /bin/fuser -k -m ${sig} ${remaining} &>/dev/null
70 sleep 5
71 retry=$((${retry} -1))
72 sig=-9
73 done
74 }
75
76 #try to unmount all filesystems (no /proc,tmpfs,devfs,etc)
77 #this is needed to make sure we dont have a mounted filesystem on a LVM volume
78 #when shutting LVM down ...
79 ebegin "Unmounting filesystems"
80 #awk should still be availible (allthough we should consider moving it to /bin if problems arise)
81 for x in $(awk '!/(^#|proc|devfs|tmpfs|^none|^\/dev\/root| \/ )/ {print $2}' /proc/mounts |sort -r)
82 do
83 umount -f -r ${x} &>/dev/null
84 done
85 eend 0
86
87 #stop LVM
88 if [ -x /sbin/vgchange -a -f /etc/lvmtab ] && [ -d /proc/lvm ]
89 then
90 ebegin "Shutting down the Logical Volume Manager"
91 /sbin/vgchange -a n >/dev/null
92 eend $? "Failed to shut LVM down"
93 fi
94
95 ups_kill_power() {
96 if [ -x /sbin/upsdrvctl ]
97 then
98 ewarn "Signalling ups driver(s) to kill the load!"
99 /sbin/upsdrvctl shutdown
100 fi
101 }
102
103 ebegin "Remounting remaining filesystems readonly"
104 #get better results with a sync and sleep
105 sync;sync
106 sleep 2
107 umount -a -r -n -t nodevfs,noproc,notmpfs &>/dev/null
108 if [ "$?" -ne 0 ]
109 then
110 killall5 -9 &>/dev/null
111 umount -a -r -n -l -d -f -t nodevfs,noproc &>/dev/null
112 if [ "$?" -ne 0 ]
113 then
114 eend 1
115 sync; sync
116 [ -f /etc/killpower ] && ups_kill_power
117 /sbin/sulogin -t 10 /dev/console
118 else
119 eend 0
120 fi
121 else
122 eend 0
123 fi
124
125 # inform if there is a forced or skipped fsck
126 if [ -f /fastboot ]
127 then
128 echo
129 ewarn "Fsck will be skipped on next startup"
130 elif [ -f /forcefsck ]
131 then
132 echo
133 ewarn "A full fsck will be forced on next startup"
134 fi
135
136 [ -f /etc/killpower ] && ups_kill_power
137
138 # vim:ts=4

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20