#!/bin/sh -e
### BEGIN INIT INFO
# Provides:          nsd3
# Required-Start:    $syslog
# Required-Stop:     $syslog
# Should-Start:      $local_fs
# Should-Stop:       $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start NSD3
# Description:       Provides an authoritative only Name Server Daemon.
### END INIT INFO

test -x /usr/sbin/nsd || exit 0
mkdir -p /var/run/nsd3 && chown -R nsd /var/run/nsd3

. /lib/lsb/init-functions
. /etc/default/rcS

ctl() {
    log_begin_msg "$3"
    start-stop-daemon --start -c "$1" --exec /usr/sbin/nsdc -- "$2" > /dev/null
    log_end_msg $?
}

nsdc() {
    start-stop-daemon --start -c nsd --exec /usr/sbin/nsdc -- "$@"
}

case "$1" in
    start)
        ctl root start   "Starting nsd3..."
        ;;
    stop)
        ctl nsd  stop    "Stopping nsd3..."
        ;;
    restart)
        ctl root restart "Restarting nsd3..."
        ;;
    reload|force-reload)
        ctl nsd  rebuild "Rebuilding nsd3 zones..."
        ctl nsd  reload  "Reloading nsd3..."
        ;;
    notify|rebuild|update)
        nsdc "$1"
        ;;
    *)
        opts=`grep '^ *[a-z|-]*)$' "$0" | tr -d ' \n' | tr ')' '|'`
        echo "Usage: /etc/init.d/nsd3 {${opts%|}}" >&2
        exit 1
        ;;
esac

exit 0
