#! /bin/sh
#
# dnsproxy		Startup script for 'dnsproxy'
#
# Written by Patrick Schoenfeld <schoenfeld@in-medias-res.com> for the Debian project
# but may be used by others.


### BEGIN INIT INFO
# Provides:          dnsproxy
# Required-Start:    $syslog $named
# Required-Stop:     $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts dnsproxy
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/dnsproxy
NAME=dnsproxy
DESC=dnsproxy

test -x $DAEMON || exit 0

RUN_DNSPROXY="false"

# Include dnsproxy defaults if available
if [ -f /etc/default/dnsproxy ] ; then
	. /etc/default/dnsproxy
fi


set -e

start()
{
	echo -n "Starting $DESC: "
	if [ "$RUN_DNSPROXY" = 'false' ]; then
		echo "not starting because it is disabled in /etc/default/dnsproxy. $NAME."
		exit 0
	fi

  	ARGS="-d -c /etc/dnsproxy.conf"
	
	if start-stop-daemon --start --quiet --exec $DAEMON -- $ARGS ; then
		echo "$NAME."
	else
		echo "$NAME is already running."
	fi
}

stop()
{
	echo -n "Stopping $DESC: "
	
	if start-stop-daemon --stop --quiet --exec $DAEMON ; then
		echo "$NAME."
	else
		echo "$NAME is not running."
	fi
}

case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart|reload|force-reload)
	stop; sleep 1; start
  	;;
  *)
	N=/etc/init.d/$NAME
	# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
