]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - etc/rc.d/local_unbound
Update compiler-rt to trunk r228651. This enables using Address
[FreeBSD/FreeBSD.git] / etc / rc.d / local_unbound
1 #!/bin/sh
2 #
3 # $FreeBSD$
4 #
5
6 # PROVIDE: local_unbound
7 # REQUIRE: FILESYSTEMS netif resolv
8 # BEFORE: NETWORKING
9 # KEYWORD: shutdown
10
11 . /etc/rc.subr
12
13 name="local_unbound"
14 desc="local caching forwarding resolver"
15 rcvar="local_unbound_enable"
16
17 command="/usr/sbin/unbound"
18 extra_commands="anchor configtest reload setup"
19 start_precmd="local_unbound_prestart"
20 reload_precmd="local_unbound_configtest"
21 anchor_cmd="local_unbound_anchor"
22 configtest_cmd="local_unbound_configtest"
23 setup_cmd="local_unbound_setup"
24 pidfile="/var/run/${name}.pid"
25
26 : ${local_unbound_workdir:=/var/unbound}
27 : ${local_unbound_config:=${local_unbound_workdir}/unbound.conf}
28 : ${local_unbound_flags:=-c${local_unbound_config}}
29 : ${local_unbound_forwardconf:=${local_unbound_workdir}/forward.conf}
30 : ${local_unbound_controlconf:=${local_unbound_workdir}/control.conf}
31 : ${local_unbound_anchor:=${local_unbound_workdir}/root.key}
32 : ${local_unbound_forwarders:=}
33
34 load_rc_config $name
35
36 do_as_unbound()
37 {
38         echo "$@" | su -m unbound
39 }
40
41 #
42 # Retrieve or update the DNSSEC root anchor
43 #
44 local_unbound_anchor()
45 {
46         do_as_unbound /usr/sbin/unbound-anchor -a ${local_unbound_anchor}
47         # we can't trust the exit code - check if the file exists
48         [ -f ${local_unbound_anchor} ]
49 }
50
51 #
52 # Check the unbound configuration file
53 #
54 local_unbound_configtest()
55 {
56         do_as_unbound /usr/sbin/unbound-checkconf ${local_unbound_config}
57 }
58
59 #
60 # Create the unbound configuration file and update resolv.conf to
61 # point to unbound.
62 #
63 local_unbound_setup()
64 {
65         echo "Performing initial setup."
66         /usr/sbin/local-unbound-setup -n \
67             -u unbound \
68             -w ${local_unbound_workdir} \
69             -c ${local_unbound_config} \
70             -f ${local_unbound_forwardconf} \
71             -o ${local_unbound_controlconf} \
72             -a ${local_unbound_anchor} \
73             ${local_unbound_forwarders}
74 }
75
76 #
77 # Before starting, check that the configuration file and root anchor
78 # exist.  If not, attempt to generate them.
79 #
80 local_unbound_prestart()
81 {
82         # Create configuration file
83         if [ ! -f ${local_unbound_config} ] ; then
84                 run_rc_command setup
85         fi
86
87         # Retrieve DNSSEC root key
88         if [ ! -f ${local_unbound_anchor} ] ; then
89                 run_rc_command anchor
90         fi
91 }
92
93 load_rc_config $name
94 run_rc_command "$1"