blob: 1a7683704524b0951b6e6a561cf57b3947d60497 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#!/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
6USE_PROCD=1
7
8START=22
9
10config_file=/etc/bind/named.conf
11config_dir=$(dirname $config_file)
12named_options_file=/etc/bind/named-rndc.conf
13rndc_conf_file=/etc/bind/rndc.conf
14pid_file=/var/run/named/named.pid
15rndc_temp=$(mktemp /tmp/rndc-confgen.XXXXXX)
16
17logdir=/var/log/named/
18cachedir=/var/cache/bind
19libdir=/var/lib/bind
20dyndir=/tmp/bind
21
22conf_local_file=$dyndir/named.conf.local
23
24
25fix_perms() {
26 for dir in $libdir $logdir $cachedir $dyndir; do
27 test -e "$dir" || {
28 mkdir -p "$dir"
29 chgrp bind "$dir"
30 chmod g+w "$dir"
31 }
32 done
33}
34
35reload_service() {
36 rndc -q reload
37}
38
39start_service() {
40 user_exists bind 57 || user_add bind 57
41 group_exists bind 57 || group_add bind 57
42 fix_perms
43
44 rndc-confgen > $rndc_temp
45
46 sed -r -n \
47 -e '/^# options \{$/,/^\};$/{ s/^/# / }' \
48 -e p \
49 -e '/^# End of rndc\.conf$/q' \
50 < $rndc_temp > $rndc_conf_file
51
52 sed -r -n \
53 -e '1,/^# End of rndc\.conf$/ { b done }' \
54 -e '/^# Use with the following in named.conf/ { p ; b done }' \
55 -e '/^# End of named\.conf$/ { p ; b done }' \
56 -e '/^# key /,$ { s/^# // ; p }' \
57 -e ': done' \
58 < $rndc_temp > $named_options_file
59
60 rm -f $rndc_temp
61
62 touch $conf_local_file
63
64 procd_open_instance
65 procd_set_param command /usr/sbin/named -u bind -f -c $config_file
66 procd_set_param file $config_file \
67 $config_dir/bind.keys \
68 $named_options_file \
69 $conf_local_file \
70 $config_dir/db.*
71 procd_set_param respawn
72 procd_close_instance
73}