svn commit: r231667 - in head: etc etc/defaults etc/rc.d share/man/man5

Doug Barton dougb at FreeBSD.org
Tue Feb 14 10:51:25 UTC 2012


Author: dougb
Date: Tue Feb 14 10:51:24 2012
New Revision: 231667
URL: http://svn.freebsd.org/changeset/base/231667

Log:
  Fix various issues with the NFS and RPC related scripts:
  
  1. Add new functionality to the force_depend method to incorporate the
     tests for whether the service is enabled and/or already running.
  2. Add a new option to bypass checking only that the service is enabled
     at boot time, and always check if it is running.
  3. Use this new functionality to greatly simplify the rc.d scripts that
     use force_depend.
  4. Add a force_depend for statd in lockd
  5. Remove the check that either nfs_server or nfs_client is _enable'd
     from statd and lockd. This was always overkill, and prevented using
     the {one|force}start options, as well as stop'ing on the command line.
  6. The yp* scripts had some of their arguments in various weird orders.
     Bring them into line with the model.
  7. If mountd fails to create /var/db/mountdtab, err out.
  
  Ideas, suggestions, and/or review from delphij and jilles.
  Pointy hats are completely my responsibility however.

Modified:
  head/etc/defaults/rc.conf
  head/etc/rc.d/amd
  head/etc/rc.d/apmd
  head/etc/rc.d/keyserv
  head/etc/rc.d/lockd
  head/etc/rc.d/mountd
  head/etc/rc.d/nfsd
  head/etc/rc.d/statd
  head/etc/rc.d/ypbind
  head/etc/rc.d/yppasswdd
  head/etc/rc.d/ypserv
  head/etc/rc.d/ypset
  head/etc/rc.d/ypupdated
  head/etc/rc.d/ypxfrd
  head/etc/rc.subr
  head/share/man/man5/rc.conf.5

Modified: head/etc/defaults/rc.conf
==============================================================================
--- head/etc/defaults/rc.conf	Tue Feb 14 10:34:27 2012	(r231666)
+++ head/etc/defaults/rc.conf	Tue Feb 14 10:51:24 2012	(r231667)
@@ -29,6 +29,8 @@ early_late_divider="FILESYSTEMS"	# Scrip
 			# stages of the boot process.  Make sure you know
 			# the ramifications if you change this.
 			# See rc.conf(5) for more details.
+always_force_depends="NO"	# Set to check that indicated dependencies are
+				# running during boot (can increase boot time).
 
 swapfile="NO"		# Set to name of swapfile if aux swapfile desired.
 apm_enable="NO"		# Set to YES to enable APM BIOS functions (or NO).

Modified: head/etc/rc.d/amd
==============================================================================
--- head/etc/rc.d/amd	Tue Feb 14 10:34:27 2012	(r231666)
+++ head/etc/rc.d/amd	Tue Feb 14 10:51:24 2012	(r231667)
@@ -19,15 +19,8 @@ extra_commands="reload"
 
 amd_precmd()
 {
-	if ! checkyesno nfs_client_enable; then
-		force_depend nfsclient || return 1
-	fi
-
-	if ! checkyesno rpcbind_enable  && \
-	    ! /etc/rc.d/rpcbind forcestatus 1>/dev/null 2>&1
-	then
-		force_depend rpcbind || return 1
-	fi
+	force_depend nfsclient nfs_client || return 1
+	force_depend rpcbind || return 1
 
 	case ${amd_map_program} in
 	[Nn][Oo] | '')
@@ -49,7 +42,6 @@ amd_precmd()
 		command_args="> /var/run/amd.pid 2> /dev/null"
 		;;
 	esac
-	return 0
 }
 
 load_rc_config $name

Modified: head/etc/rc.d/apmd
==============================================================================
--- head/etc/rc.d/apmd	Tue Feb 14 10:34:27 2012	(r231666)
+++ head/etc/rc.d/apmd	Tue Feb 14 10:51:24 2012	(r231667)
@@ -19,24 +19,18 @@ apmd_prestart()
 {
 	case `${SYSCTL_N} hw.machine_arch` in
 	i386)
-		# Enable apm if it is not already enabled
-		if ! checkyesno apm_enable  && \
-		    ! /etc/rc.d/apm forcestatus 1>/dev/null 2>&1
-		then
-			force_depend apm || return 1
-		fi
+		force_depend apm || return 1
 
 		# Warn user about acpi apm compatibility support which
 		# does not work with apmd.
 		if [ ! -e /dev/apmctl ]; then
-		    warn "/dev/apmctl not found; kernel is missing apm(4)"
+			warn "/dev/apmctl not found; kernel is missing apm(4)"
 		fi
 		;;
 	*)
 		return 1
 		;;
 	esac
-	return 0
 }
 
 load_rc_config $name

Modified: head/etc/rc.d/keyserv
==============================================================================
--- head/etc/rc.d/keyserv	Tue Feb 14 10:34:27 2012	(r231666)
+++ head/etc/rc.d/keyserv	Tue Feb 14 10:51:24 2012	(r231667)
@@ -19,13 +19,7 @@ start_precmd="keyserv_prestart"
 
 keyserv_prestart()
 {
-	if ! checkyesno rpcbind_enable  && \
-		! /etc/rc.d/rpcbind forcestatus 1>/dev/null 2>&1
-	then
-		force_depend rpcbind || return 1
-	fi
-
-	return 0
+	force_depend rpcbind || return 1
 }
 
 load_rc_config $name

Modified: head/etc/rc.d/lockd
==============================================================================
--- head/etc/rc.d/lockd	Tue Feb 14 10:34:27 2012	(r231666)
+++ head/etc/rc.d/lockd	Tue Feb 14 10:51:24 2012	(r231667)
@@ -15,28 +15,16 @@ name="lockd"
 rcvar=rpc_lockd_enable
 command="/usr/sbin/rpc.${name}"
 start_precmd='lockd_precmd'
-stop_precmd='checkyesno nfs_server_enable || checkyesno nfs_client_enable'
-status_precmd=$stop_precmd
 
 # Make sure that we are either an NFS client or server, and that we get
 # the correct flags from rc.conf(5).
 #
 lockd_precmd()
 {
-	local ret
-	ret=0
-
-	if ! checkyesno nfs_server_enable && ! checkyesno nfs_client_enable
-	then
-		ret=1
-	fi
-	if ! checkyesno rpcbind_enable && \
-	    ! /etc/rc.d/rpcbind forcestatus 1>/dev/null 2>&1
-	then
-		force_depend rpcbind || ret=1
-	fi
+	force_depend rpcbind || return 1
+	force_depend statd rpc_statd || return 1
+	
 	rc_flags=${rpc_lockd_flags}
-	return ${ret}
 }
 
 load_rc_config $name

Modified: head/etc/rc.d/mountd
==============================================================================
--- head/etc/rc.d/mountd	Tue Feb 14 10:34:27 2012	(r231666)
+++ head/etc/rc.d/mountd	Tue Feb 14 10:51:24 2012	(r231667)
@@ -19,11 +19,7 @@ extra_commands="reload"
 
 mountd_precmd()
 {
-	if ! checkyesno rpcbind_enable  && \
-	    ! /etc/rc.d/rpcbind forcestatus 1>/dev/null 2>&1
-	then
-		force_depend rpcbind || return 1
-	fi
+	force_depend rpcbind || return 1
 
 	# mountd flags will differ depending on rc.conf settings
 	#
@@ -48,8 +44,8 @@ mountd_precmd()
 	fi
 
 	rm -f /var/db/mountdtab
-	( umask 022 ; > /var/db/mountdtab )
-	return 0
+	( umask 022 ; > /var/db/mountdtab ) ||
+	    err 1 'Cannot create /var/db/mountdtab'
 }
 
 load_rc_config $name

Modified: head/etc/rc.d/nfsd
==============================================================================
--- head/etc/rc.d/nfsd	Tue Feb 14 10:34:27 2012	(r231666)
+++ head/etc/rc.d/nfsd	Tue Feb 14 10:51:24 2012	(r231667)
@@ -48,31 +48,15 @@ nfsd_precmd()
 
 		if checkyesno nfsv4_server_enable; then
 			sysctl vfs.nfsd.server_max_nfsvers=4 > /dev/null
-			if ! checkyesno nfsuserd_enable  && \
-			    ! /etc/rc.d/nfsuserd forcestatus 1>/dev/null 2>&1
-			then
-				if ! force_depend nfsuserd; then
-					err 1 "Cannot run nfsuserd"
-				fi
-			fi
+			force_depend nfsuserd || err 1 "Cannot run nfsuserd"
 		else
 			echo 'NFSv4 is disabled'
 			sysctl vfs.nfsd.server_max_nfsvers=3 > /dev/null
 		fi
 	fi
 
-	if ! checkyesno rpcbind_enable  && \
-	    ! /etc/rc.d/rpcbind forcestatus 1>/dev/null 2>&1
-	then
-		force_depend rpcbind || return 1
-	fi
-
-	if ! checkyesno mountd_enable  && \
-	    ! /etc/rc.d/mountd forcestatus 1>/dev/null 2>&1
-	then
-		force_depend mountd || return 1
-	fi
-	return 0
+	force_depend rpcbind || return 1
+	force_depend mountd || return 1
 }
 
 run_rc_command "$1"

Modified: head/etc/rc.d/statd
==============================================================================
--- head/etc/rc.d/statd	Tue Feb 14 10:34:27 2012	(r231666)
+++ head/etc/rc.d/statd	Tue Feb 14 10:51:24 2012	(r231667)
@@ -15,28 +15,15 @@ name="statd"
 rcvar=rpc_statd_enable
 command="/usr/sbin/rpc.${name}"
 start_precmd='statd_precmd'
-stop_precmd='checkyesno nfs_server_enable || checkyesno nfs_client_enable'
-status_precmd=$stop_precmd
 
 # Make sure that we are either an NFS client or server, and that we get
 # the correct flags from rc.conf(5).
 #
 statd_precmd()
 {
-	local ret
-	ret=0
-
-	if ! checkyesno nfs_server_enable && ! checkyesno nfs_client_enable
-	then
-		ret=1
-	fi
-	if ! checkyesno rpcbind_enable && \
-	    ! /etc/rc.d/rpcbind forcestatus 1>/dev/null 2>&1
-	then
-		force_depend rpcbind || ret=1
-	fi
+	force_depend rpcbind || return 1
+	
 	rc_flags=${rpc_statd_flags}
-	return ${ret}
 }
 
 load_rc_config $name

Modified: head/etc/rc.d/ypbind
==============================================================================
--- head/etc/rc.d/ypbind	Tue Feb 14 10:34:27 2012	(r231666)
+++ head/etc/rc.d/ypbind	Tue Feb 14 10:51:24 2012	(r231667)
@@ -11,22 +11,20 @@
 . /etc/rc.subr
 
 name="ypbind"
-command="/usr/sbin/${name}"
-start_precmd="ypbind_precmd"
+rcvar="nis_client_enable"
 
 load_rc_config $name
-rcvar="nis_client_enable"
+
+command="/usr/sbin/${name}"
 command_args="${nis_client_flags}"
 
+start_precmd="ypbind_precmd"
+
 ypbind_precmd()
 {
 	local _domain
 
-	if ! checkyesno rpcbind_enable  && \
-	    ! /etc/rc.d/rpcbind forcestatus 1>/dev/null 2>&1
-	then
-		force_depend rpcbind || return 1
-	fi
+	force_depend rpcbind || return 1
 
 	_domain=`domainname`
 	if [ -z "$_domain" ]; then

Modified: head/etc/rc.d/yppasswdd
==============================================================================
--- head/etc/rc.d/yppasswdd	Tue Feb 14 10:34:27 2012	(r231666)
+++ head/etc/rc.d/yppasswdd	Tue Feb 14 10:51:24 2012	(r231667)
@@ -11,27 +11,22 @@
 . /etc/rc.subr
 
 name="yppasswdd"
-command="/usr/sbin/rpc.${name}"
-start_precmd="yppasswdd_precmd"
+rcvar="nis_yppasswdd_enable"
 
 load_rc_config $name
-rcvar="nis_yppasswdd_enable"
+
+command="/usr/sbin/rpc.${name}"
 command_args="${nis_yppasswdd_flags}"
 
+start_precmd="yppasswdd_precmd"
+
 yppasswdd_precmd()
 {
 	local _domain
 
-	if ! checkyesno rpcbind_enable  && \
-	    ! /etc/rc.d/rpcbind forcestatus 1>/dev/null 2>&1
-	then
-		force_depend rpcbind || return 1
-	fi
-	if ! checkyesno nis_server_enable && \
-	    ! /etc/rc.d/ypserv forcestatus 1>/dev/null 2>&1
-	then
-		force_depend ypserv || return 1
-	fi
+	force_depend rpcbind || return 1
+	force_depend ypserv nis_server || return 1
+	
 	_domain=`domainname`
 	if [ -z "$_domain" ]; then
 		warn "NIS domainname(1) is not set."

Modified: head/etc/rc.d/ypserv
==============================================================================
--- head/etc/rc.d/ypserv	Tue Feb 14 10:34:27 2012	(r231666)
+++ head/etc/rc.d/ypserv	Tue Feb 14 10:51:24 2012	(r231667)
@@ -11,21 +11,20 @@
 
 name="ypserv"
 rcvar="nis_server_enable"
-command="/usr/sbin/${name}"
-start_precmd="ypserv_prestart"
 
 load_rc_config $name
+
+command="/usr/sbin/${name}"
 command_args="${nis_server_flags}"
 
+start_precmd="ypserv_prestart"
+
 ypserv_prestart()
 {
 	local _domain
 
-	if ! checkyesno rpcbind_enable  && \
-	    ! /etc/rc.d/rpcbind forcestatus 1>/dev/null 2>&1
-	then
-		force_depend rpcbind || return 1
-	fi
+	force_depend rpcbind || return 1
+
 	_domain=`domainname`
 	if [ -z "$_domain" ]; then
 		warn "NIS domainname(1) is not set."

Modified: head/etc/rc.d/ypset
==============================================================================
--- head/etc/rc.d/ypset	Tue Feb 14 10:34:27 2012	(r231666)
+++ head/etc/rc.d/ypset	Tue Feb 14 10:51:24 2012	(r231667)
@@ -11,25 +11,20 @@
 
 name="ypset"
 rcvar="nis_ypset_enable"
-command="/usr/sbin/${name}"
-start_precmd="ypset_precmd"
+
 load_rc_config $name
+
+command="/usr/sbin/${name}"
 command_args="${nis_ypset_flags}"
 
+start_precmd="ypset_precmd"
+
 ypset_precmd()
 {
 	local _domain
 
-	if ! checkyesno rpcbind_enable  && \
-	    ! /etc/rc.d/rpcbind forcestatus 1>/dev/null 2>&1
-	then
-		force_depend rpcbind || return 1
-	fi
-	if ! checkyesno nis_client_enable && \
-	    ! /etc/rc.d/ypbind forcestatus 1>/dev/null 2>&1
-	then
-		force_depend ypbind || return 1
-	fi
+	force_depend rpcbind || return 1
+	force_depend ypbind nis_client || return 1
 
 	_domain=`domainname`
 	if [ -z "$_domain" ]; then

Modified: head/etc/rc.d/ypupdated
==============================================================================
--- head/etc/rc.d/ypupdated	Tue Feb 14 10:34:27 2012	(r231666)
+++ head/etc/rc.d/ypupdated	Tue Feb 14 10:51:24 2012	(r231667)
@@ -11,6 +11,9 @@
 
 name="ypupdated"
 rcvar="rpc_ypupdated_enable"
+
+load_rc_config $name
+
 command="/usr/sbin/rpc.${name}"
 start_precmd="rpc_ypupdated_precmd"
 
@@ -18,16 +21,8 @@ rpc_ypupdated_precmd()
 {
 	local _domain
 
-	if ! checkyesno rpcbind_enable  && \
-	    ! /etc/rc.d/rpcbind forcestatus 1>/dev/null 2>&1
-	then
-		force_depend rpcbind || return 1
-	fi
-	if ! checkyesno nis_server_enable && \
-	    ! /etc/rc.d/ypserv forcestatus 1>/dev/null 2>&1
-	then
-		force_depend ypserv || return 1
-	fi
+	force_depend rpcbind || return 1
+	force_depend ypserv nis_server || return 1
 
 	_domain=`domainname`
 	if [ -z "$_domain" ]; then
@@ -36,5 +31,4 @@ rpc_ypupdated_precmd()
 	fi
 }
 
-load_rc_config $name
 run_rc_command "$1"

Modified: head/etc/rc.d/ypxfrd
==============================================================================
--- head/etc/rc.d/ypxfrd	Tue Feb 14 10:34:27 2012	(r231666)
+++ head/etc/rc.d/ypxfrd	Tue Feb 14 10:51:24 2012	(r231667)
@@ -11,25 +11,20 @@
 
 name="ypxfrd"
 rcvar="nis_ypxfrd_enable"
-command="/usr/sbin/rpc.${name}"
-start_precmd="ypxfrd_precmd"
+
 load_rc_config $name
+
+command="/usr/sbin/rpc.${name}"
 command_args="${nis_ypxfrd_flags}"
 
+start_precmd="ypxfrd_precmd"
+
 ypxfrd_precmd()
 {
 	local _domain
 
-	if ! checkyesno rpcbind_enable  && \
-	    ! /etc/rc.d/rpcbind forcestatus 1>/dev/null 2>&1
-	then
-		force_depend rpcbind || return 1
-	fi
-	if ! checkyesno nis_server_enable && \
-	    ! /etc/rc.d/ypserv forcestatus 1>/dev/null 2>&1
-	then
-		force_depend ypserv || return 1
-	fi
+	force_depend rpcbind || return 1
+	force_depend ypserv nis_server || return 1
 
 	_domain=`domainname`
 	if [ -z "$_domain" ]; then

Modified: head/etc/rc.subr
==============================================================================
--- head/etc/rc.subr	Tue Feb 14 10:34:27 2012	(r231666)
+++ head/etc/rc.subr	Tue Feb 14 10:51:24 2012	(r231667)
@@ -71,22 +71,29 @@ set_rcvar_obsolete()
 }
 
 #
-# force_depend script
+# force_depend script [rcvar]
 #	Force a service to start. Intended for use by services
-#	to resolve dependency issues. It is assumed the caller
-#	has check to make sure this call is necessary
+#	to resolve dependency issues.
 #	$1 - filename of script, in /etc/rc.d, to run
+#	$2 - name of the script's rcvar (minus the _enable)
 #
 force_depend()
 {
+	local _depend _dep_rcvar
+
 	_depend="$1"
+	_dep_rcvar="${2:-$1}_enable"
+
+	[ -n "$rc_fast" ] && ! checkyesno always_force_depends &&
+	    checkyesno $_dep_rcvar && return 0
+
+	/etc/rc.d/${_depend} forcestatus >/dev/null 2>&1 && return 0
 
 	info "${name} depends on ${_depend}, which will be forced to start."
 	if ! /etc/rc.d/${_depend} forcestart; then
 		warn "Unable to force ${_depend}. It may already be running."
 		return 1
 	fi
-	return 0
 }
 
 #

Modified: head/share/man/man5/rc.conf.5
==============================================================================
--- head/share/man/man5/rc.conf.5	Tue Feb 14 10:34:27 2012	(r231666)
+++ head/share/man/man5/rc.conf.5	Tue Feb 14 10:51:24 2012	(r231667)
@@ -24,7 +24,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd February 8, 2012
+.Dd February 11, 2012
 .Dt RC.CONF 5
 .Os
 .Sh NAME
@@ -149,6 +149,19 @@ and before changing it one should ensure
 adequate provisions to recover from a failed boot
 (such as physical contact with the machine,
 or reliable remote console access).
+.It Va always_force_depends
+.Pq Vt bool
+Various
+.Pa rc.d
+scripts use the force_depend function to check whether required
+services are already running, and to start them if necessary.
+By default during boot time this check is bypassed if the
+required service is enabled in
+.Pa /etc/rc.conf[.local] .
+Setting this option will bypass that check at boot time and
+always test whether or not the service is actually running.
+Enabling this option is likely to increase your boot time if
+services are enabled that utilize the force_depend check.
 .It Va swapfile
 .Pq Vt str
 If set to


More information about the svn-src-all mailing list