#!/bin/sh
# 
# dnsmasq

set +e   # Don't exit on error status

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/dnsmasq
NAME=dnsmasq
DESC="DNS forwarder and DHCP server"
OPTS="-k -i lo -a 127.0.0.1 -z"
DSMETOOL=/usr/sbin/dsmetool

# Most configuration options in /etc/default/dnsmasq are deprecated
# but still honoured.

if [ -r /etc/default/$NAME ]; then
	. /etc/default/$NAME
fi

test -x $DAEMON || exit 0

case "$1" in
  start)
	echo -n "Starting $DESC: "
	if [ -x $DSMETOOL ]; then
	    $DSMETOOL -n -1 -t "$DAEMON $OPTS"
	else
	    start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
		--exec $DAEMON
	fi
	echo "$NAME."
	;;
  stop)
	echo -n "Stopping $DESC: "
	if [ -x $DSMETOOL ]; then
	    $DSMETOOL -k "$DAEMON $OPTS"
	else
	    start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
		--name $NAME	
	fi
	echo "$NAME."
	;;
  restart|force-reload)
	"$0" stop
	"$0" start
	;;
  *)
	echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload}" >&2
	exit 3
	;;
esac

exit 0

