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