summaryrefslogtreecommitdiff
path: root/dns/dnsdist/files/dnsdist.in
blob: 3ece4c66bc01103dcddc3d89213673092f98251a (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
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
#!/bin/sh

# PROVIDE: dnsdist
# REQUIRE: FILESYSTEMS defaultroute netwait resolv
# BEFORE: NETWORKING
# KEYWORD: shutdown
#
# Add the following line to /etc/rc.conf to enable dnsdist:
#
# dnsdist_enable="YES"
#
# Multiple profiles are supported with
#
# dnsdist_profiles="name1 name2"
# dnsdist_name1_enable="YES"
# dnsdist_name1_config="/path/to/config1"
# dnsdist_name2_enable="YES"
# dnsdist_name2_config="/path/to/config2"
#
# This script does't validate uid/gid per profile (yet)
# It still uses the default or definition of
# dnsdist_priv_user and/or dnsdist_priv_group
#

. /etc/rc.subr

desc="dnsdist is a powerful, scriptable DNS loadbalancer"
name=dnsdist
rcvar=dnsdist_enable

load_rc_config ${name}

: ${dnsdist_enable:=NO}
: ${dnsdist_config:=%%ETCDIR%%/dnsdist.conf}
: ${dnsdist_priv_user:=_dnsdist}
: ${dnsdist_priv_group:=_dnsdist}

pidfile="/var/run/${name}.pid"
required_files=${dnsdist_config}
actual_command="%%PREFIX%%/sbin/${name} -C ${dnsdist_config} -u ${dnsdist_priv_user} -g ${dnsdist_priv_group} --supervised"
command=/usr/sbin/daemon
command_args="-c -f -r -P ${pidfile} -- ${actual_command}"

if [ -n "$2" ]; then
	profile="$2"
	if [ "x${dnsdist_profiles}" != "x" ]; then
		eval dnsdist_config="\${dnsdist_${profile}_config:-%%ETCDIR%%/dnsdist-${profile}.conf}"
		if [ "x${dnsdist_config}" = "x" ]; then
			echo "You must define a configuration file (dnsdist_${profile}_config)" >&2
			exit 1
		fi
		eval dnsdist_enable="\${dnsdist_${profile}_enable:-${dnsdist_enable}}"
		pidfile="/var/run/${name}-${profile}.pid"
		required_files="${dnsdist_config}"
		actual_command="%%PREFIX%%/sbin/${name} -C ${dnsdist_config} -u ${dnsdist_priv_user} -g ${dnsdist_priv_group} --supervised"
		command_args="-c -f -r -P ${pidfile} -- ${actual_command}"
	else
		echo "$0: extra argument ignored" >&2
	fi
else
	if [ "x${dnsdist_profiles}" != "x" -a "x$1" != "x" ]; then
		for profile in ${dnsdist_profiles}; do
			eval _enable="\${dnsdist_${profile}_enable}"
			case "x${_enable:-${dnsdist_enable}}" in
			x|x[Nn][Oo]|x[Nn][Oo][Nn][Ee])
				continue
				;;
			x[Yy][Ee][Ss])
				;;
			*)
				if test -z "$_enable"; then
					_var=dnsdist_enable
				else
					_var=dnsdist_"${profile}"_enable
				fi
				echo "Bad value" \
					"'${_enable:-${dnsdist_enable}}'" \
					"for ${_var}. " \
					"Profile ${profile} skipped." >&2
				continue
				;;
			esac
			echo "===> dnsdist profile: ${profile}" >&2
			%%PREFIX%%/etc/rc.d/dnsdist $1 ${profile}
			retcode="$?"
			if [ "0${retcode}" -ne 0 ]; then
				failed="${profile} (${retcode}) ${failed:-}"
			else
				success="${profile} ${success:-}"
		fi
		done
		exit 0
	fi
fi

start_precmd=dnsdist_startprecmd

dnsdist_startprecmd()
{
        if [ ! -e ${pidfile} ]; then
                install -o ${dnsdist_priv_user} -g ${dnsdist_priv_group} /dev/null ${pidfile};
        fi
}

run_rc_command "$1"