summaryrefslogtreecommitdiffstats
path: root/net/kea/files/kea.init
blob: 259861ae5fe34ace67a65ced17318ba4d3c70cf3 (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
#!/bin/sh /etc/rc.common

USE_PROCD=1
START=25
STOP=85

LIB_PATH="/usr/lib/kea"
BIN_PATH="/usr/sbin"
CONF_PATH="/etc/kea"

start_service() {
	mkdir --mode=0750 -p /var/lib/kea /var/run/kea

	config_load "kea"
	config_foreach start_kea "service"
}

start_kea() {
	local cfg="$1"
	local name cmd cnf importer

	config_get_bool disabled "$cfg" disabled 0
	[ "$disabled" = "0" ] || return

	config_get name "$cfg" name "$cfg"

	case "$name" in
		ctrl_agent|dhcp4|dhcp6|dhcp_ddns)
			;;
		*)
			echo "Error: Invalid service name '$name'" >&2
			return 1
			;;
	esac

	name="${name/_/-}"
	cmd="${BIN_PATH}/kea-${name}"
	cnf="${CONF_PATH}/kea-${name}.conf"
	importer="${LIB_PATH}/importers/${name}.sh"

	if [ -f "$importer" ]; then
		if ! "$importer" "$cnf"; then
			echo "Error: Importer '$importer' failed; aborting." >&2
			return 1
		fi
	fi

	procd_open_instance "$name"
	procd_set_param command "$cmd" -c "$cnf"
	procd_set_param env KEA_LOCKFILE_DIR=/tmp
	procd_append_param env KEA_PIDFILE_DIR=/tmp
	procd_set_param file "$cnf"
	procd_set_param stderr 1
	procd_set_param stdout 1
	procd_close_instance
}