bind: start up with -4 if not listening on ipv6 addresses
[feed/packages.git] / net / bind / files / named.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2014 Noah Meyerhans <frodo@morgul.net>
3 # Licensed under the terms of the GNU General Public License version 2
4 # or (at your discretion) any later later version
5
6 USE_PROCD=1
7
8 START=22
9
10 config_file=/etc/bind/named.conf
11 config_dir=$(dirname $config_file)
12 named_options_file=/etc/bind/named-rndc.conf
13 rndc_conf_file=/etc/bind/rndc.conf
14 pid_file=/var/run/named/named.pid
15
16 logdir=/var/log/named/
17 cachedir=/var/cache/bind
18 libdir=/var/lib/bind
19 dyndir=/tmp/bind
20
21 conf_local_file=$dyndir/named.conf.local
22
23 fix_perms() {
24 for dir in $libdir $logdir $cachedir $dyndir; do
25 test -e "$dir" || {
26 mkdir -p "$dir"
27 chgrp bind "$dir"
28 chmod g+w "$dir"
29 }
30 done
31 }
32
33 no_ipv6() {
34 [ -z "$(ip -6 -o route show default)" ]
35 }
36
37 reload_service() {
38 rndc -q reload
39 }
40
41 start_service() {
42 user_exists bind 57 || user_add bind 57
43 group_exists bind 57 || group_add bind 57
44 fix_perms
45
46 local runnamed=$(dirname $pid_file)
47 # with dropped privileges, we need this created for us
48 [ -d $runnamed ] || {
49 mkdir -m 0755 $runnamed
50 chown bind.bind $runnamed
51 }
52
53 local rndc_temp=$(mktemp /tmp/rndc-confgen.XXXXXX)
54
55 rndc-confgen > $rndc_temp
56
57 sed -r -n \
58 -e '/^# options \{$/,/^\};$/{ s/^/# / }' \
59 -e p \
60 -e '/^# End of rndc\.conf$/q' \
61 < $rndc_temp > $rndc_conf_file
62
63 sed -r -n \
64 -e '1,/^# End of rndc\.conf$/ { b done }' \
65 -e '/^# Use with the following in named.conf/ { p ; b done }' \
66 -e '/^# End of named\.conf$/ { p ; b done }' \
67 -e '/^# key /,$ { s/^# // ; p }' \
68 -e ': done' \
69 < $rndc_temp > $named_options_file
70
71 rm -f $rndc_temp
72
73 touch $conf_local_file
74
75 local args=
76 [ no_ipv6 ] && args="-4"
77
78 procd_open_instance
79 procd_set_param command /usr/sbin/named -u bind -f $args -c $config_file
80 procd_set_param file $config_file \
81 $config_dir/bind.keys \
82 $named_options_file \
83 $conf_local_file \
84 $config_dir/db.*
85 procd_set_param respawn
86 procd_close_instance
87 }