How to get djbdns to start early enough to satisfy ntpd at boot?

Ben Morrow ben at morrow.me.uk
Thu Jan 15 04:00:21 PST 2009


Quoth Andrew Reilly <andrew-freebsd at areilly.bpc-users.org>:
> 
> So: does anyone know how to modify the boot-time order so that
> svscan starts at (or before) the point in the boot cycle where
> BIND would, on other systems?  I suspect that it should be
> possible by changing the PROVIDE: in svscan.sh to include one of
> the things REQUIRE:'d by ntpd.  Or perhaps the REQUIRE: LOGIN in
> svscan.sh is incompatible with the BEFORE: LOGIN in ntpd?
> 
> Has any other user of dnscache encountered and solved this
> problem?

I have, in my svscan.sh,

    # PROVIDE: svscan
    # REQUIRE: SERVERS cleanvar

and I also have a /usr/local/etc/rc.d/dnscache which looks like

    #!/bin/sh

    # PROVIDE: named
    # REQUIRE: svscan

    . /etc/rc.subr
    . /usr/local/etc/svc.subr

    name="dnscache"
    rcvar=`set_rcvar`

    : ${dnscache_enable:="NO"}

    load_rc_config $name
    load_svc_subr_config

    run_rc_command "$1"

and a /usr/local/etc/svc.subr as attached. It's somewhat more general
than is needed for dnscache, as I also use it to start qmail.

Basically: the PROVIDE: named line is needed to get dnscache up before
ntpd, and the REQUIRE: LOGIN line needs to be changed.

Ben

-------------- next part --------------
#
# Subroutines for handling services under the control of svscan(8).
# Requires rc.subr is loaded first.
#

load_svc_subr_config () {
	load_rc_config_var svscan svscan_servicedir

	: ${svscan_servicedir:=/var/service}
	: ${svc:=/usr/local/bin/svc}
	: ${svok:=/usr/local/bin/svok}
	: ${svstat:=/usr/local/bin/svstat}

	: ${svcname:=${name}}	
	: ${service_dir:=${svscan_servicedir}/${svcname}}
	: ${svok_timeout:=30}
	: ${svstat_timeout:=30}

	: ${start_cmd:=svc_subr_start}
	: ${stop_cmd:=svc_subr_stop}
	: ${restart_cmd:=svc_subr_restart}

	: ${extra_commands:="status reload flush"}
	: ${status_cmd:=svc_subr_status}
	: ${reload_cmd:=svc_subr_reload}
	: ${flush_cmd:=svc_subr_flush}
}

svc_subr_isup () {
	$svstat $1 | grep -q ": up"
}

svc_subr_isdown () {
 	$svstat $1 | grep -q ": down"
}

svc_subr_waitfor () {
	local n check timeout err

	check="$1"
	timeout=$2
	err="$3"

	n=0
	while [ $n -lt $timeout ] && ! $check $service_dir
	do
		sleep 1
		n=$(( n + 1 ))
	done

	if ! $check $service_dir
	then
		echo "$err" >&2
		exit 1
	fi
}

svc_subr_start () {

	echo -n "Checking ${name} is up"

	svc_subr_waitfor $svok $svok_timeout \
		"supervise is not running in ${service_dir}!"

	$svc -u $service_dir

	svc_subr_waitfor svc_subr_isup $svstat_timeout \
		"${service_dir} won't come up!"

	echo "."
}

svc_subr_stop () {

	echo -n "Bringing ${name} down"

	$svc -d $service_dir

	svc_subr_waitfor svc_subr_isdown $svstat_timeout \
		"${service_dir} won't come down, trying SIGKILL"

	svc -k $service_dir

	svc_subr_waitfor svc_subr_isdown $svstat_timeout \
		"${service_dir} won't come down!"

	echo "."
}

svc_subr_restart () {
	echo -n "Sending ${name} a SIGTERM"
	$svc -t $service_dir
	echo "."
}

svc_subr_reload () {
	echo -n "Sending ${name} a SIGHUP"
	$svc -h $service_dir
	echo "."
}

svc_subr_flush () {
	echo -n "Sending ${name} a SIGALRM"
	$svc -a $service_dir
	echo "."
}

svc_subr_status () {
	$svstat $service_dir
}


More information about the freebsd-stable mailing list