#!/usr/bin/env /lib/runit/invoke-run
#Copyright: 2026 Lorenzo Puliti <plorenzo@disroot.org>
#License: BSD-3-Clause

exec 2>&1

#run it as is to use the default config; to create a '2' instance do:
#cp /etc/powerdns/recursor.conf /etc/powerdns/recursor-2.conf
#cpsv p pdns-recursor@default pdns-recursor@2 ; update-service --add pdns-recursor@2

INSTANCE=${PWD##*@}; CONFIG=recursor-${PWD##*@};
if [ "$INSTANCE" = 'default' ]; then INSTANCE= ; CONFIG=recursor; fi

ulimit -n 16384

#config check
[ -r "/etc/powerdns/$CONFIG.conf" ] || exit 162
##bin##  --config=check --config-name=${INSTANCE:-} || exit 162

install -o pdns -g pdns -d /run/pdns-recursor

exec ##bin## --config-name=${INSTANCE:-}  --daemon=no --write-pid=no --setuid=pdns --setgid=pdns --disable-syslog
#NOTE: issue: sv reload -> restarts the service instead of reloading
