#!/bin/sh
#
# pdns		Proxy DNS Daemon
#
# chkconfig:	345 14 89
#
# description:	Proxy DNS Daemon
#

# Source function library
. /etc/rc.d/init.d/functions

# Get network config
. /etc/sysconfig/network

# Default parameters
STATUS="--status"
DEBUG="--debug"
VERBOSE="-v2"

# Get service config - may override defaults
[ -f /etc/sysconfig/pdnsd ] && . /etc/sysconfig/pdnsd

# Check that networking is up.
if is_no "${NETWORKING}"; then
	msg_Network_Down Pdnsd
	exit 1
fi

test -x /usr/sbin/pdnsd || exit 0

case "$1" in
  start)
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/pdns ]; then
		msg_starting Pdns
		daemon pdnsd --daemon $STATUS $DEBUG $VERBOSE
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/pdns
	else
		msg_Already_Running Pdns
		exit 1
	fi
	;;
  stop)
	# Stop daemons.
	# show "Stopping %s service" pdns
	if [ -f /var/lock/subsys/pdns ]; then
		msg_stopping Pdns
		killproc pdnsd
		rm -f /var/lock/subsys/pdns >/dev/null 2>&1
	else
		msg_Not_Running Pdns
		exit 1
	fi
	;;
  restart)
	$0 stop
	$0 start
	;;
  reload)
	if [ -f /var/lock/subsys/pdns ]; then
		msg_show Pdns
		msg_reload
		busy
		killproc pdnsd -HUP
		deltext
		ok
	else
		msg_Not_Running Pdns
		exit 1
	fi
	;;
  force-reload)
	# if program allows reloading without stopping
	$0 reload
	exit $?

	# or if it doesn't
	$0 stop && $0 start
	exit $?
	;;
  status)
	status pdnsd
	exit $?
	;;
  *)
	# show "Usage: %s {start|stop|status|restart|reload|force-reload}" $0
	msg_Usage "$0 {start|stop|status|restart|reload|force-reload}"
	exit 1
esac

exit $RETVAL
