Lines 2-42
Link Here
|
2 |
# |
2 |
# |
3 |
# $FreeBSD$ |
3 |
# $FreeBSD$ |
4 |
# |
4 |
# |
5 |
# unbound freebsd startup rc.d script, modified from the named script. |
5 |
# unbound freebsd startup rc.d script |
6 |
# uses the default unbound installation path and pidfile location. |
6 |
# uses the default unbound installation path and pidfile location. |
7 |
# copy this to /etc/rc.d/unbound |
7 |
# copy this to %%PREFIX%%/etc/rc.d/unbound |
8 |
# and put unbound_enable="YES" into rc.conf |
8 |
# and put unbound_enable="YES" into rc.conf |
9 |
# |
9 |
# |
10 |
# unbound_anchorflags can be used to allow you to pass a custom flags to |
10 |
# unbound_anchorflags can be used to allow you to pass a custom flags to |
11 |
# unbound-anchor. Examples include a custom resolv.conf (-f) or a custom |
11 |
# unbound-anchor. Examples include a custom resolv.conf (-f) or a custom |
12 |
# root.hints (-r). Useful for when /etc/resolv.conf only contains 127.0.0.1 |
12 |
# root.hints (-r). Useful for when /etc/resolv.conf only contains 127.0.0.1 |
13 |
|
13 |
# |
14 |
# PROVIDE: unbound |
14 |
# PROVIDE: unbound |
15 |
# REQUIRE: SERVERS cleanvar |
15 |
# REQUIRE: DAEMON |
|
|
16 |
# REQUIRE: LOGIN |
16 |
# KEYWORD: shutdown |
17 |
# KEYWORD: shutdown |
|
|
18 |
# |
19 |
# Add the following line to /etc/rc.conf to enable unbound: |
20 |
# |
21 |
# unbound_enable="YES" |
22 |
# |
23 |
# You could set alternative config with |
24 |
# unbound_config="/path/to/config" |
25 |
# |
26 |
# |
27 |
# Multiple profiles are supported with |
28 |
# |
29 |
# unbound_profiles="name1 name2" |
30 |
# unbound_name1_enable="YES" |
31 |
# unbound_name1_config="/path/to/config1" |
32 |
# unbound_name2_enable="YES" |
33 |
# unbound_name2_config="/path/to/config2" |
34 |
# |
35 |
# A fib can be set for each profile as in |
36 |
# unbound_name1_fib=1 |
37 |
# |
17 |
|
38 |
|
18 |
. /etc/rc.subr |
39 |
. /etc/rc.subr |
19 |
|
40 |
|
20 |
name="unbound" |
41 |
name=unbound |
21 |
rcvar=unbound_enable |
42 |
rcvar=unbound_enable |
22 |
|
43 |
|
23 |
command="%%PREFIX%%/sbin/unbound" |
44 |
# setfib |
24 |
extra_commands="reload" |
45 |
unbound_startfib() { |
25 |
start_precmd="start_precmd" |
46 |
${SYSCTL} net.fibs >/dev/null 2>&1 || return 0 |
26 |
|
47 |
|
27 |
load_rc_config $name |
48 |
unbound_fib=${unbound_fib:-"NONE"} |
|
|
49 |
case "$unbound_fib" in |
50 |
[Nn][Oo][Nn][Ee]) |
51 |
;; |
52 |
*) |
53 |
echo "Using fib #: " $unbound_fib . |
54 |
command="setfib -F ${unbound_fib} ${command}" |
55 |
;; |
56 |
esac |
57 |
} |
28 |
|
58 |
|
29 |
pidfile=`%%PREFIX%%/sbin/unbound-checkconf -o pidfile ${unbound_conf}` |
|
|
30 |
unbound_enable=${unbound_enable:-"NO"} |
31 |
unbound_anchorflags=${unbound_anchorflags:-""} |
32 |
unbound_conf=${unbound_conf:-"%%ETCDIR%%/unbound.conf"} |
33 |
unbound_flags=${unbound_flags:-" -c ${unbound_conf}"} |
34 |
|
35 |
reload_precmd="%%PREFIX%%/sbin/unbound-checkconf ${unbound_conf} >/dev/null" |
36 |
|
37 |
start_precmd() |
59 |
start_precmd() |
38 |
{ |
60 |
{ |
39 |
echo -n "Obtaining a trust anchor:" |
61 |
unbound_startfib |
|
|
62 |
|
63 |
echo -n "Obtaining a trust anchor.." |
40 |
if [ "${unbound_anchorflags}T" = "T" ]; then |
64 |
if [ "${unbound_anchorflags}T" = "T" ]; then |
41 |
su -m unbound -c %%PREFIX%%/sbin/unbound-anchor |
65 |
su -m unbound -c %%PREFIX%%/sbin/unbound-anchor |
42 |
else |
66 |
else |
Lines 47-50
Link Here
|
47 |
return $? |
71 |
return $? |
48 |
} |
72 |
} |
49 |
|
73 |
|
|
|
74 |
# read settings, set default values |
75 |
load_rc_config "${name}" |
76 |
: ${unbound_enable:="NO"} |
77 |
: ${unbound_config:=%%PREFIX%%/etc/unbound/unbound.conf} |
78 |
|
79 |
# Set PID file |
80 |
pidfile=$(%%PREFIX%%/sbin/unbound-checkconf -o pidfile %%PREFIX%%/etc/unbound/unbound.conf) |
81 |
|
82 |
required_files=${unbound_config} |
83 |
command="%%PREFIX%%/sbin/${name}" |
84 |
command_args="-c ${unbound_config}" |
85 |
unbound_anchorflags=${unbound_anchorflags:-""} |
86 |
extra_commands="reload" |
87 |
start_precmd="start_precmd" |
88 |
reload_precmd="%%PREFIX%%/sbin/unbound-checkconf ${unbound_conf} >/dev/null" |
89 |
|
90 |
load_rc_config "${name}" |
91 |
|
92 |
if [ -n "$2" ]; then |
93 |
profile="$2" |
94 |
if [ "x${unbound_profiles}" != "x" ]; then |
95 |
eval unbound_config="\${unbound_${profile}_config:-%%PREFIX%%/etc/unbound/unbound-${profile}.conf}" |
96 |
eval unbound_fib="\${unbound_${profile}_fib:-${unbound_fib}}" |
97 |
if [ "x${unbound_config}" = "x" ]; then |
98 |
echo "You must define a configuration file (unbound_${profile}_config)" |
99 |
exit 1 |
100 |
fi |
101 |
|
102 |
# Replace default value with profile-based (defined in the config file) |
103 |
_cfgpidfile=$(%%PREFIX%%/sbin/unbound-checkconf -o pidfile ${unbound_config}) |
104 |
_defaultpidfile=$(%%PREFIX%%/sbin/unbound-checkconf -o pidfile /dev/null) |
105 |
|
106 |
if [ "x${_cfgpidfile}" = "x" -o "x${_cfgpidfile}" = "x${_defaultpidfile}" ] ; then |
107 |
pidfile=${_defaultpidfile} |
108 |
else |
109 |
pidfile=${_cfgpidfile} |
110 |
fi |
111 |
required_files="${unbound_config}" |
112 |
eval unbound_enable="\${unbound_${profile}_enable:-${unbound_enable}}" |
113 |
command_args="-c ${unbound_config}" |
114 |
else |
115 |
echo "$0: extra argument ignored" |
116 |
fi |
117 |
else |
118 |
if [ "x${unbound_profiles}" != "x" -a "x$1" != "x" ]; then |
119 |
for profile in ${unbound_profiles}; do |
120 |
eval _enable="\${unbound_${profile}_enable}" |
121 |
case "x${_enable:-${unbound_enable}}" in |
122 |
x|x[Nn][Oo]|x[Nn][Oo][Nn][Ee]) |
123 |
continue |
124 |
;; |
125 |
x[Yy][Ee][Ss]) |
126 |
;; |
127 |
*) |
128 |
if test -z "$_enable"; then |
129 |
_var=unbound_enable |
130 |
else |
131 |
_var=unbound_"${profile}"_enable |
132 |
fi |
133 |
echo "Bad value" \ |
134 |
"'${_enable:-${unbound_enable}}'" \ |
135 |
"for ${_var}. " \ |
136 |
"Profile ${profile} skipped." |
137 |
continue |
138 |
;; |
139 |
esac |
140 |
echo "===> unbound profile: ${profile}" |
141 |
%%PREFIX%%/etc/rc.d/unbound $1 ${profile} |
142 |
retcode="$?" |
143 |
if [ "0${retcode}" -ne 0 ]; then |
144 |
failed="${profile} (${retcode}) ${failed:-}" |
145 |
else |
146 |
success="${profile} ${success:-}" |
147 |
fi |
148 |
done |
149 |
exit 0 |
150 |
fi |
151 |
fi |
152 |
|
50 |
run_rc_command "$1" |
153 |
run_rc_command "$1" |