#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

PID=`pidof -o %PPID @prefix@/sbin/pdnsd`

start() {
  stat_busy "Starting PDNSD"
  [ -z "$PID" ] && @prefix@/sbin/pdnsd -d -c /etc/pdnsd.conf
  if [ $? -gt 0 ]; then
    stat_fail
  else
    add_daemon pdnsd
    stat_done
  fi
}

stop() {
  stat_busy "Stopping PDNSD"
  [ ! -z "$PID" ]  && kill $PID &> /dev/null
  if [ $? -gt 0 ]; then
    stat_fail
  else
    rm_daemon pdnsd
    stat_done
  fi
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    $0 stop
    sleep 2
    $0 start
    ;;
  *)
    echo "usage: $0 {start|stop|restart}"  
esac
exit 0
