#!/bin/sh
#
# $Id: dhcp3-server.init.d,v 1.4 2003/07/13 19:12:41 mdz Exp $
#

test -f /usr/sbin/dhcpd3 || exit 0

# It is not safe to start if we don't have a default configuration...
if [ ! -f /etc/default/dhcp3-server ]; then
	echo "/etc/default/dhcp3-server does not exist! - Aborting..."
	echo "Run 'dpkg-reconfigure dhcp3-server' to fix the problem."
	exit 0
fi

# Read init script configuration (so far only interfaces the daemon
# should listen on.)
. /etc/default/dhcp3-server

DHCPDPID=/var/run/dhcpd.pid

case "$1" in
	start)
		echo -n "Starting DHCP server: "
		start-stop-daemon --start --quiet --pidfile $DHCPDPID \
			--exec /usr/sbin/dhcpd3 -- -q $INTERFACES
		sleep 2

		if [ -f "$DHCPDPID" ] && ps h `cat "$DHCPDPID"` >/dev/null; then
			echo "dhcpd3."
		else
			echo "dhcpd3 failed to start - check syslog for diagnostics."
			exit 1
		fi
		;;
	stop)
		echo -n "Stopping DHCP server: dhcpd3"
		start-stop-daemon --stop --quiet --pidfile $DHCPDPID
		echo "."
		;;
	restart | force-reload)
		$0 stop
		sleep 2
		$0 start
		if [ "$?" != "0" ]; then
			exit 1
		fi
		;;
	*)
		echo "Usage: /etc/init.d/dhcp3-server {start|stop|restart|force-reload}"
		exit 1 
esac

exit 0
