7c61b5e2a89f60cbf1039e56866e90d6974ffbd1
[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 reload_service() {
34 rndc -q reload
35 }
36
37 start_service() {
38 user_exists bind 57 || user_add bind 57
39 group_exists bind 57 || group_add bind 57
40 fix_perms
41
42 local runnamed=$(dirname $pid_file)
43 # with dropped privileges, we need this created for us
44 [ -d $runnamed ] || {
45 mkdir -m 0755 $runnamed
46 chown bind.bind $runnamed
47 }
48
49 local rndc_temp=$(mktemp /tmp/rndc-confgen.XXXXXX)
50
51 rndc-confgen > $rndc_temp
52
53 sed -r -n \
54 -e '/^# options \{$/,/^\};$/{ s/^/# / }' \
55 -e p \
56 -e '/^# End of rndc\.conf$/q' \
57 < $rndc_temp > $rndc_conf_file
58
59 sed -r -n \
60 -e '1,/^# End of rndc\.conf$/ { b done }' \
61 -e '/^# Use with the following in named.conf/ { p ; b done }' \
62 -e '/^# End of named\.conf$/ { p ; b done }' \
63 -e '/^# key /,$ { s/^# // ; p }' \
64 -e ': done' \
65 < $rndc_temp > $named_options_file
66
67 rm -f $rndc_temp
68
69 touch $conf_local_file
70
71 procd_open_instance
72 procd_set_param command /usr/sbin/named -u bind -f -c $config_file
73 procd_set_param file $config_file \
74 $config_dir/bind.keys \
75 $named_options_file \
76 $conf_local_file \
77 $config_dir/db.*
78 procd_set_param respawn
79 procd_close_instance
80 }