6 # PROVIDE: local_unbound
7 # REQUIRE: FILESYSTEMS defaultroute netwait resolv
14 desc="Local caching forwarding resolver"
15 rcvar="local_unbound_enable"
17 command="/usr/sbin/local-unbound"
18 extra_commands="anchor configtest reload setup"
19 start_precmd="local_unbound_prestart"
20 start_postcmd="local_unbound_poststart"
21 reload_precmd="local_unbound_configtest"
22 anchor_cmd="local_unbound_anchor"
23 configtest_cmd="local_unbound_configtest"
24 setup_cmd="local_unbound_setup"
25 pidfile="/var/run/${name}.pid"
29 : ${local_unbound_workdir:=/var/unbound}
30 : ${local_unbound_config:=${local_unbound_workdir}/unbound.conf}
31 : ${local_unbound_flags:="-c ${local_unbound_config}"}
32 : ${local_unbound_forwardconf:=${local_unbound_workdir}/forward.conf}
33 : ${local_unbound_controlconf:=${local_unbound_workdir}/control.conf}
34 : ${local_unbound_anchor:=${local_unbound_workdir}/root.key}
35 : ${local_unbound_forwarders:=}
36 : ${local_unbound_tls:=}
37 : ${local_unbound_pidfile:=${pidfile}}
38 pidfile=${local_unbound_pidfile}
42 echo "$@" | su -m unbound
46 # Retrieve or update the DNSSEC root anchor
48 local_unbound_anchor()
50 do_as_unbound ${command}-anchor -a ${local_unbound_anchor}
51 # we can't trust the exit code - check if the file exists
52 [ -f ${local_unbound_anchor} ]
56 # Check the unbound configuration file
58 local_unbound_configtest()
60 do_as_unbound ${command}-checkconf ${local_unbound_config}
64 # Create the unbound configuration file and update resolv.conf to
70 if checkyesno local_unbound_tls ; then
73 echo "Performing initial setup."
76 -w ${local_unbound_workdir} \
77 -c ${local_unbound_config} \
78 -f ${local_unbound_forwardconf} \
79 -o ${local_unbound_controlconf} \
80 -a ${local_unbound_anchor} \
82 ${local_unbound_forwarders}
86 # Before starting, check that the configuration file and root anchor
87 # exist. If not, attempt to generate them.
89 local_unbound_prestart()
91 # Create configuration file
92 if [ ! -f ${local_unbound_config} ] ; then
96 # Retrieve DNSSEC root key
97 if [ ! -s ${local_unbound_anchor} ] ; then
103 # After starting, wait for Unbound to report that it is ready to avoid
104 # race conditions with services which require functioning DNS.
106 local_unbound_poststart()
110 echo -n "Waiting for nameserver to start..."
111 until "${command}-control" -c "${local_unbound_config}" status | grep -q "is running" ; do
112 if [ $((retry -= 1)) -eq 0 ] ; then