#!/bin/sh
# SPDX-FileCopyrightText: 2001-2026 Univention GmbH
# SPDX-License-Identifier: AGPL-3.0-only

case "$1" in
	start)
		PATH=/sbin:/bin:/usr/sbin:/usr/bin
		debug_level="$(ucr get dns/debug/level)"
		max_socks="$(ucr get dns/max-socks)"

		exec /usr/sbin/named -c /etc/bind/named.conf -p 7777 -u bind -f -d ${debug_level:-0} ${max_socks:+-S "$max_socks"}
		;;
	reload)
		/usr/sbin/rndc -p 55555 reload
		;;
	stop)
		/usr/sbin/rndc -p 55555 stop
		;;
	wait-for-startup)
		timeout="$(ucr get dns/timeout-start)"
		/usr/bin/timeout "${timeout:-120}" /bin/sh -c \
			"until rndc -p 55555 status | grep --quiet 'server is up and running'; do sleep 1; done"
		;;
esac
