6 # PROVIDE: local_unbound
7 # REQUIRE: FILESYSTEMS netif resolv
14 desc="Local caching forwarding resolver"
15 rcvar="local_unbound_enable"
17 command="/usr/sbin/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:=}
39 echo "$@" | su -m unbound
43 # Retrieve or update the DNSSEC root anchor
45 local_unbound_anchor()
47 do_as_unbound /usr/sbin/unbound-anchor -a ${local_unbound_anchor}
48 # we can't trust the exit code - check if the file exists
49 [ -f ${local_unbound_anchor} ]
53 # Check the unbound configuration file
55 local_unbound_configtest()
57 do_as_unbound /usr/sbin/unbound-checkconf ${local_unbound_config}
61 # Create the unbound configuration file and update resolv.conf to
66 echo "Performing initial setup."
67 /usr/sbin/local-unbound-setup -n \
69 -w ${local_unbound_workdir} \
70 -c ${local_unbound_config} \
71 -f ${local_unbound_forwardconf} \
72 -o ${local_unbound_controlconf} \
73 -a ${local_unbound_anchor} \
74 ${local_unbound_forwarders}
78 # Before starting, check that the configuration file and root anchor
79 # exist. If not, attempt to generate them.
81 local_unbound_prestart()
83 # Create configuration file
84 if [ ! -f ${local_unbound_config} ] ; then
88 # Retrieve DNSSEC root key
89 if [ ! -f ${local_unbound_anchor} ] ; then
95 # After starting, wait for Unbound to report that it is ready to avoid
96 # race conditions with services which require functioning DNS.
98 local_unbound_poststart()
102 echo -n "Waiting for nameserver to start..."
103 until "${command}-control" status | grep -q "is running" ; do
104 if [ $((retry -= 1)) -eq 0 ] ; then