b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 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 | rndc_temp=$(mktemp /tmp/rndc-confgen.XXXXXX) |
| 16 | |
| 17 | logdir=/var/log/named/ |
| 18 | cachedir=/var/cache/bind |
| 19 | libdir=/var/lib/bind |
| 20 | dyndir=/tmp/bind |
| 21 | |
| 22 | conf_local_file=$dyndir/named.conf.local |
| 23 | |
| 24 | |
| 25 | fix_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 | |
| 35 | reload_service() { |
| 36 | rndc -q reload |
| 37 | } |
| 38 | |
| 39 | start_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 | } |