#!/bin/sh
#
# MacPorts generated daemondo support script
#

#
# Init
#
prefix=/opt/local

#
# Start
#
Start()
{
	('/opt/local/sbin/unbound-anchor' -a '/opt/local/etc/unbound/root.key' 2>&1) \
	    || : && (chown unbound:unbound '/opt/local/etc/unbound/root.key' 2>&1) \
	    && (for i in '/opt/local/etc/unbound/unbound'*conf; \
	        do '/opt/local/sbin/unbound' -c "$i" 2>&1; done)
}

#
# Stop
#
Stop()
{
	(for i in '/opt/local/var/run/unbound/unbound'*pid; \
	    do /bin/kill -15 $(cat "$i") 2>&1; done)
}

#
# Restart
#
Restart()
{
	Stop
	Start
}

#
# Run
#
Run()
{
case $1 in
  start  ) Start   ;;
  stop   ) Stop    ;;
  restart) Restart ;;
  *      ) echo "$0: unknown argument: $1";;
esac
}

#
# Run a phase based on the selector
#
Run $1

