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