/[baselayout]/branches/rc-scripts-1_6/init.d/netmount
Gentoo

Contents of /branches/rc-scripts-1_6/init.d/netmount

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1231 - (show annotations) (download)
Mon Jun 13 02:25:31 2005 UTC (9 years, 2 months ago) by vapier
File size: 2767 byte(s)
merge cvs Header removal from trunk
1 #!/sbin/runscript
2 # Copyright 1999-2005 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4
5 depend() {
6 local myneed="net"
7 local myuse=""
8
9 # Only have Portmap as a dependency if there is a nfs mount in fstab
10 # that should be mounted at boot time. Also filter out comments.
11 local nfsmounts=$(awk '!/^#/ && ($3=="nfs" || $3=="nfs4") && $4 !~ /noauto/ { print $0 }' /etc/fstab)
12
13 if [ -n "${nfsmounts}" ]
14 then
15 myneed="${myneed} portmap"
16 myuse="${myuse} nfs nfsmount"
17 fi
18
19 need ${myneed}
20 use ${myuse}
21 }
22
23 start() {
24 local rcfilesystems=""
25
26 # Only try to mount NFS filesystems if portmap was started.
27 # This is to fix "hang" problems for new users who do not
28 # add portmap to the default runlevel.
29 if [ -L "${svcdir}/started/portmap" ]
30 then
31 rcfilesystems="${NET_FS_LIST// /,}" # convert to comma-separated
32 else
33 rcfilesystems=" ${NET_FS_LIST} "
34 rcfilesystems=${rcfilesystems// nfs /} # remove nfs
35 rcfilesystems=${rcfilesystems// nfs4 /} # remove nfs4
36 rcfilesystems=${rcfilesystems# } # remove front and
37 rcfilesystems=${rcfilesystems% } # back spaces
38 rcfilesystems=${rcfilesystems// /,} # convert to comma-separated
39 fi
40
41 ebegin "Mounting network filesystems"
42 mount -at ${rcfilesystems} >/dev/null
43
44 if [ "$?" -ne 0 ]
45 then
46 ewend 1 "Could not mount all network filesystems!"
47 else
48 eend 0
49 fi
50
51 return 0
52 }
53
54 stop() {
55 local ret
56 ebegin "Unmounting network filesystems"
57 [ -z "$(umount -art ${NET_FS_LIST// /,} 2>&1)" ]
58 ret=$?
59 eend ${ret} "Failed to simply unmount filesystems"
60 [ ${ret} -eq 0 ] && return 0
61
62 # `umount -a` will fail if the filesystems are in use.
63 # Here we use fuser to kill off processes that are using
64 # the filesystems so that we can unmount properly.
65 # We will gradually use harsher kill signals so that the
66 # processes know we aren't screwing around here ;).
67 declare -a siglist=( "TERM" "KILL" "KILL" )
68 local retry=0
69 local remaining="go"
70
71 while [ -n "${remaining}" -a ${retry} -lt 3 ]
72 do
73 # Populate $remaining with a newline-delimited list of network
74 # filesystems. Mount points have spaces swapped for '\040' (see
75 # fstab(5)) so we have to translate them back to spaces.
76 remaining="$(awk '$3 ~ /'${NET_FS_LIST// /|}'/ { if ($2 != "/") print $2 }' /proc/mounts | sort -r)"
77 # Since we have to worry about the spaces being quoted properly,
78 # we'll use `set --` and then "$@" to get the correct result.
79 IFS=$'\n'
80 set -- ${remaining//\\040/ }
81 unset IFS
82 [ -z "${remaining}" ] && break
83
84 # try to unmount again
85 ebegin $'\t'"Unmounting network filesystems (retry #$((retry+1)))"
86 /bin/fuser -k -${siglist[$((retry++))]} -m "$@" &>/dev/null
87 sleep 5
88 umount "$@" &>/dev/null
89 eend $? $'\t'"Failed to unmount filesystems"
90 done
91 }
92
93 # 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