#!/bin/sh
#
# $NetBSD: kea.sh,v 1.1 2022/12/19 07:44:50 sekiya Exp $
#
# PROVIDE: kea
# REQUIRE: DAEMON
# BEFORE: LOGIN
#
# You will need to set some variables in /etc/rc.conf to start Kea:
#
# kea=YES

name="kea"

if [ -f /etc/rc.subr ]; then
	. /etc/rc.subr

	rcvar=$name
	command="/usr/pkg/sbin/keactrl"
	command_args="start"
	required_files="/usr/pkg/etc/kea/keactrl.conf"
	extra_commands="reload"
	stop_cmd="/usr/pkg/sbin/keactrl stop"
	reload_cmd="/usr/pkg/sbin/keactrl reload"

	load_rc_config $name
	run_rc_command "$1"
else
	ctl_command="/usr/pkg/sbin/keactrl"

	if [ ! -x ${ctl_command} ]; then
		return
	fi

	case "$1" in
	start)
		echo "Starting ${name}."
		${ctl_command} start
		;;
	stop)
		echo "Stopping ${name}."
		${ctl_command} stop
		;;
	reload)
		${ctl_command} reload
		;;
	restart)
		"$0" stop
		sleep 10
		"$0" start
		;;
	*)
		${ctl_command} "$1"
		;;
	esac
fi
