#!/bin/sh
#
# pdnsd	DNS server
#
# chkconfig: 345 90 10
# description: a caching dns proxy for small networks or dialin accounts
# processname: pdnsd
# config: /etc/pdnsd.conf
# pidfile: /var/run/pdnsd.pid

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

CONFIGFILE=/etc/pdnsd.conf
PIDFILE=/var/run/pdnsd.pid
LOCKFILE=/var/lock/subsys/pdnsd
RETVAL=0

start()
{
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user pdnsd -- \
		pdnsd --daemon --config-file "$CONFIGFILE" -p "$PIDFILE"
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user pdnsd pdnsd
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	sleep 2
	start
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload|restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload
		fi
		;;
	status)
		status --pidfile "$PIDFILE" --expect-user pdnsd pdnsd
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
