summaryrefslogtreecommitdiff
path: root/dns/knot3/files/knot.in
blob: df885ed7c9c29645d5422d427080cb9367212808 (plain) (blame)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/sh

# PROVIDE: knot
# REQUIRE: SERVERS cleanvar
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable knot:
#
# knot_enable="YES":	Set to NO by default.
#			Set it to YES to enable knot.
# knot_config="":	Set to %%PREFIX%%/etc/knot/knot.conf
#			by default.
#
# -----------------------------------------------------------------------------
#
# This script supports running multiple instances of knot.
# To run additional instances link this script to something like
# % ln -s knot knot_foo
# and define additional knot_foo_* variables in one of
# /etc/rc.conf, /etc/rc.conf.local or /etc/rc.conf.d/knot_foo
#
# Below NAME should be substituted with the name of this script. By default
# it is knot, so read as knot_enable. If you linked the script to
# knot_foo, then read as knot_foo_enable etc.
#
# The following variables are supported (defaults are shown).
# You can place them in any of
# /etc/rc.conf, /etc/rc.conf.local or /etc/rc.conf.d/NAME
#
# NAME_enable="NO"	# set to YES to enable knot
#
# # optional:
# NAME_config="%%PREFIX%%/etc/knot/NAME.conf"  # (-c)onfig file
# NAME_config="db:/var/db/knot/confdb"         # (-C)onfig database
# NAME_diruser="%%USERS%%"    # /var/db/NAME and /var/run/NAME are created if they
# NAME_dirgroup="%%GROUPS%%"  # don't exist. These don't control the user/group knot
#                       # runs as, the config file has a setting for that.
#
# You also need to set the rundir directive in the server section of the
# config file to /var/run/NAME (if using a NAME other than the default)
# and you will want the storage directive(s) declared in the zone section
# to point to /var/db/NAME overriding the default of /var/db/knot.
#
# For further documentation, please see knot.conf(5).

. /etc/rc.subr

case "$0" in
/etc/rc*)
	# during boot (shutdown) $0 is /etc/rc (/etc/rc.shutdown),
	# so get the name of the script from $_file
	name="$_file"
	;;
*)
	name="$0"
	;;
esac

name="${name##*/}"
rcvar=${name}_enable

load_rc_config ${name}

eval ": \${${name}_enable:=\"NO\"}"
eval ": \${${name}_config:=\"%%PREFIX%%/etc/knot/${name}.conf\"}"
eval ": \${${name}_diruser:=\"%%USERS%%\"}"
eval ": \${${name}_dirgroup:=\"%%GROUPS%%\"}"
eval ": \${${name}_svcj_options:=\"net_basic\"}"

configfile="$(eval echo \${${name}_config})"
diruser="$(eval echo \${${name}_diruser})"
dirgroup="$(eval echo \${${name}_dirgroup})"

command=%%PREFIX%%/sbin/knotd
case "$configfile" in
db:*)
	config_args="-C ${configfile#db:}"
	;;
*)
	config_args="-c ${configfile}"
	;;
esac
command_args="${config_args} -d"
control="%%PREFIX%%/sbin/knotc"
pidfile="/var/run/${name}/knot.pid"

case "$configfile" in
db:*)
	required_files=${configfile#db:}/data.mdb
	;;
*)
	required_files=${configfile}
	;;
esac

extra_commands=reload
reload_cmd="knot_reload"
start_precmd="knot_prestart"

knot_prestart()
{
	if [ ! -d /var/run/${name} ]; then
		install -d -o ${diruser} -g ${dirgroup} /var/run/${name}
	fi
	if [ ! -d /var/db/${name} ]; then
		install -d -o ${diruser} -g ${dirgroup} /var/db/${name}
	fi
	${control} ${config_args} conf-check
}

knot_reload()
{
	echo "Reloading ${name}."
	${control} ${config_args} reload
}

run_rc_command "$1"