#!/bin/sh
# chkconfig: - 80 75
# description: pdns_recursor is a versatile high performance recursing nameserver

prefix=/usr
exec_prefix=${prefix}
BINARYPATH=${exec_prefix}/bin
SBINARYPATH=${exec_prefix}/sbin
SOCKETPATH=/var/run

PIDFILE=/var/run/pdns_recursor.pid

if [ -s $PIDFILE -a -d /proc/$(cat $PIDFILE) 2>/dev/null ] 
then
	RUNNING=1
	PID=$(cat $PIDFILE)
else
	RUNNING=0
fi


case "$1" in
	status)
		if [ $RUNNING = "1" ]
		then
			echo pdns_recursor is running
		else
			echo pdns_recursor is not running
		fi
	;;
	
	stop)
		echo -n "Stopping PowerDNS recursor: "
		if [ $RUNNING = "1" ]
		then
			kill -9  $PID
			echo stopped
		else
			echo not running
		fi
	;;

	start)
		echo -n "Starting PowerDNS recursor: "
		if [ $RUNNING = "1" ]
		then
			echo already running
		else
			$SBINARYPATH/pdns_recursor --daemon > /dev/null 2> /dev/null
			echo started
		fi
	;;

	restart)
		$0 stop
		$0 start
	;;

	*)
		echo unknown instruction \'$1\'
	;;

esac
		

