#! /bin/sh

#
# /etc/rc.d/init.d/S30dhcpd - Start/Stop the DHCP server daemon(s).
#

# Comment out the following exit line to enable this script.
# Before doing so, you need to edit the /etc/dhcpd.conf file.
exit 0

KILLWAIT=3
DAEMON="dhcpd"

if [ ! -x /sbin/ip ]; then
	echo "$0: Missing /sbin/ip"
	exit 1
fi

case "$1" in

    start)
	# Ensure eth1 device is there
	if ! ip link | grep -q 'eth1'; then
		echo "$0: Network interface eth0 not present" >&2
		exit 2
	fi

	echo "Starting ${DAEMON}"
	${DAEMON} eth1
	if [ "$?" = "0" ]; then echo "Done"
	else                    echo "FAILED"; fi
	sleep 1
	;;

    stop)
	echo "Stopping ${DAEMON}"
	killall ${DAEMON}
	sleep ${KILLWAIT}
	killall -9 ${DAEMON}
	if [ "$?" = "0" ]; then echo "Done"
	else                    echo "FAILED"; fi
	;;

    restart)
	$0 stop
	sleep 1
	$0 start
	;;

    *)
	echo "Usage: $0 (start|stop|restart)"
	exit 1
	;;

esac

exit 0

