/[baselayout]/branches/baselayout-1_12/init.d/netmount
Gentoo

Contents of /branches/baselayout-1_12/init.d/netmount

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3066 - (show annotations) (download)
Sun Oct 28 23:33:10 2007 UTC (8 years, 10 months ago) by vapier
File size: 3291 byte(s)
use openafs-client as well #196919
1 #!/sbin/runscript
2 # Copyright 1999-2007 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4
5 # Since NFS is so common and it's possible to mount it without needing
6 # any additional daemon overhead, we'll account for it here.
7
8 depend() {
9 # We list so many filesystems here so that people can do "use netmount"
10 # in their init.d scripts and not worry about random net filesystem scripts.
11 local myneed="" myuse=""
12 local nfs_mounts=$(awk '!/^[[:space:]]*#/ && ($3=="nfs" || $3=="nfs4") && $4 !~ /\<(noauto|nolock)\>/ { print $0 }' /etc/fstab)
13 if [[ -n ${nfs_mounts} ]] ; then
14 myneed="${myneed} portmap"
15 else
16 myuse="${myuse} portmap"
17 fi
18 need net ${myneed}
19 use afs-client openafs-client amd autofs nfs nfsmount ${myuse}
20 }
21
22 remove_net_fs() {
23 local fs
24 rcfilesystems=" ${rcfilesystems} "
25 for fs in "$@" ; do
26 rcfilesystems=${rcfilesystems// ${fs} / }
27 done
28 rcfilesystems=${rcfilesystems# } # remove front and
29 rcfilesystems=${rcfilesystems% } # back spaces
30 }
31
32 start() {
33 local rcfilesystems=${NET_FS_LIST}
34
35 # If the nfsmount script took care of the nfs filesystems,
36 # then there's no point in trying them twice
37 if service_started nfsmount ; then
38 remove_net_fs nfs nfs4
39 else
40 # Only try to mount NFS filesystems if portmap was started.
41 # This is to fix "hang" problems for new users who do not
42 # add portmap to the default runlevel.
43 local nfs_mounts=$(awk '!/^[[:space:]]*#/ && ($3=="nfs" || $3=="nfs4") && $4 !~ /\<(noauto|nolock)\>/ { print $0 }' /etc/fstab)
44 if ! service_started portmap && [[ -n ${nfs_mounts} ]] ; then
45 remove_net_fs nfs nfs4
46 fi
47 fi
48
49 rcfilesystems=${rcfilesystems// /,} # convert to comma-separated
50
51 ebegin "Mounting network filesystems"
52 mount -at ${rcfilesystems}
53 ewend $? "Could not mount all network filesystems!"
54
55 return 0
56 }
57
58 stop() {
59 local rcfilesystems=${NET_FS_LIST}
60
61 rcfilesystems=${rcfilesystems// /,} # convert to comma-separated
62
63 ebegin "Unmounting network filesystems"
64 [[ -z $(umount -art ${rcfilesystems} 2>&1) ]]
65 eend $? "Failed to simply unmount filesystems"
66 [[ $? == 0 ]] && return 0
67
68 # `umount -a` will fail if the filesystems are in use.
69 # Here we use fuser to kill off processes that are using
70 # the filesystems so that we can unmount properly.
71 # We will gradually use harsher kill signals so that the
72 # processes know we aren't screwing around here ;).
73 declare -a siglist=( "TERM" "KILL" "KILL" )
74 local retry=0
75 local remaining="go"
76
77 while [[ -n ${remaining} && ${retry} -lt 3 ]] ; do
78 # Populate $remaining with a newline-delimited list of network
79 # filesystems. Mount points have spaces swapped for '\040' (see
80 # fstab(5)) so we have to translate them back to spaces.
81 remaining="$(awk '$3 ~ /'${NET_FS_LIST// /|}'/ { if ($2 != "/") print $2 }' /proc/mounts | sort -r)"
82 # Since we have to worry about the spaces being quoted properly,
83 # we'll use `set --` and then "$@" to get the correct result.
84 IFS=$'\n'
85 set -- ${remaining//\\040/ }
86 unset IFS
87 [[ -z ${remaining} ]] && break
88
89 # try to unmount again
90 ebegin $'\t'"Unmounting network filesystems (retry #$((retry+1)))"
91 /bin/fuser -s -k -${siglist[$((retry++))]} -m "$@"
92 sleep 5
93 umount "$@" &>/dev/null
94 eend $? $'\t'"Failed to unmount filesystems"
95 done
96
97 return 0
98 }
99
100 # 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