#!/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)"
		test -z $debug_level && debug_level=0

		OPTS="-c /etc/bind/named.conf.proxy -u bind -f -d $debug_level"

		max_socks="$(ucr get dns/max-socks)"
		if [ -n "$max_socks" ]; then
			OPTS="$OPTS -S $max_socks"
		fi

		exec /usr/sbin/named $OPTS
		;;
	reload)
		/usr/sbin/rndc -p 953 reload
		;;
	stop)
		/usr/sbin/rndc -p 953 stop
		;;
	wait-for-startup)
		/usr/bin/timeout 30 /bin/sh -c \
			"until rndc -p 953 status | grep --quiet 'server is up and running'; do sleep 1; done"
		;;
esac
