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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 144 - (show annotations) (download) (as text)
Sun Mar 10 22:57:28 2002 UTC (17 years, 8 months ago) by azarah
File MIME type: text/x-sh
File size: 3045 byte(s)
lost of fixes

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 ebegin "Remounting remaining filesystems readonly"
96 #get better results with a sync and sleep
97 sync;sync
98 sleep 2
99 umount -a -r -n -t nodevfs,noproc,notmpfs &>/dev/null
100 if [ "$?" -ne 0 ]
101 then
102 killall5 -9 &>/dev/null
103 umount -a -r -n -l -d -f &>/dev/null
104 if [ "$?" -ne 0 ]
105 then
106 eend 1
107 sync; sync
108 /sbin/sulogin -t 10 /dev/console
109 else
110 eend 0
111 fi
112 else
113 eend 0
114 fi
115
116
117 # 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