1#!/bin/sh
2#
3# $FreeBSD$
4#
5
6# PROVIDE: mountcritremote
7# REQUIRE: NETWORKING FILESYSTEMS ipsec netwait
8# KEYWORD: nojail
9
10. /etc/rc.subr
11
12name="mountcritremote"
13desc="Mount critical remote filesystems"
14stop_cmd=":"
15start_cmd="mountcritremote_start"
16start_precmd="mountcritremote_precmd"
17
18# Mount NFS filesystems if present in /etc/fstab
19#
20# XXX When the vfsload() issues with nfsclient support and related sysctls
21# have been resolved, this block can be removed, and the condition that
22# skips nfs in the following block (for "other network filesystems") can
23# be removed.
24#
25mountcritremote_precmd()
26{
27	case "`mount -d -a -t nfs 2> /dev/null`" in
28	*mount_nfs*)
29		# Handle absent nfs client support
30		load_kld -m nfs nfscl || return 1
31		;;
32	esac
33	return 0
34}
35
36mountcritremote_start()
37{
38	local mounted_remote_filesystem=false
39
40	# Mount nfs filesystems.
41	#
42	case "`/sbin/mount -d -a -t nfs`" in
43	'')
44		;;
45	*)
46		mounted_remote_filesystem=true
47		echo -n 'Mounting NFS filesystems:'
48		mount -a -t nfs
49		echo '.'
50		;;
51	esac
52
53	# Mount other network filesystems if present in /etc/fstab.
54	case ${extra_netfs_types} in
55	[Nn][Oo])
56		;;
57	*)
58		netfs_types="${netfs_types} ${extra_netfs_types}"
59		;;
60	esac
61
62	for i in ${netfs_types}; do
63		fstype=${i%:*}
64		fsdecr=${i#*:}
65
66		[ "${fstype}" = "nfs" ] && continue
67
68		case "`mount -d -a -t ${fstype}`" in
69		*mount_${fstype}*)
70			mounted_remote_filesystem=true
71			echo -n "Mounting ${fsdecr} filesystems:"
72			mount -a -t ${fstype}
73			echo '.'
74			;;
75		esac
76	done
77
78	if $mounted_remote_filesystem; then
79		# Cleanup /var again just in case it's a network mount.
80		/etc/rc.d/cleanvar quietreload
81		rm -f /var/run/clean_var /var/spool/lock/clean_var
82
83		# Regenerate the ldconfig hints in case there are additional
84		# library paths on remote file systems
85		/etc/rc.d/ldconfig quietstart
86	fi
87}
88
89load_rc_config $name
90run_rc_command "$1"
91