summaryrefslogtreecommitdiffstats
path: root/net/bind/files/named.init
blob: e626149c43e19574b3365a6da70bc6a03e62814c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/sh /etc/rc.common
# Copyright (C) 2014 Noah Meyerhans <frodo@morgul.net>
# Licensed under the terms of the GNU General Public License version 2
# or (at your discretion) any later later version

# shellcheck disable=SC2034
USE_PROCD=1
START=22

config_dir=/etc/bind
run_dir=/var/run/named
log_dir=/var/log/named
cache_dir=/var/cache/bind
zone_dir=$config_dir/zones
lib_dir=/var/lib/bind

config_file=$config_dir/named.conf

reload_service() {
	rndc -q reload
}

stop_service() {
	rndc stop
}

start_service() {
	user_exists bind 57 || user_add bind 57
	group_exists bind 57 || group_add bind 57

	for dir in $run_dir $log_dir $cache_dir $zone_dir; do
		if [ ! -e "$dir" ]; then
			mkdir -p "$dir"
		fi
		chown bind:bind "$dir"
		chmod 0775 "$dir"
	done

	if [ ! -e $lib_dir ]; then
		mkdir -p "$(dirname $lib_dir)"
		ln -sf $zone_dir $lib_dir
	fi

	if [ ! -s /etc/bind/rndc.key ] && [ ! -s /etc/bind/rndc.conf ]; then
		rndc-confgen -a
		chown bind:bind /etc/bind/rndc.key
		chmod 0640 /etc/bind/rndc.key
	fi

	procd_open_instance
	procd_set_param command /usr/sbin/named -u bind -f -c $config_file
	procd_set_param file $config_file $config_dir/db.*
	procd_set_param respawn
	procd_close_instance
}