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