#!/bin/bash

# startDHCPD
#
# Usage:
#    startDHCPD
#
# Description:
#    This script starts the DHCPD daemon for the console
#
# Return Codes
#    0: normal script termination; no unrecoverable errors
#    1: error starting the DHCPD daemon
#
# Module History
#    00  10/13/2003  T. Forties  - Initial Release
#    00  02/08/2004  T. Forties  - Start DHCPD without specifying lan by name
#        02/07/2008  M. Clark    - Use killall to make sure dhcpd is gone

LANID=$1

# Dump out the process id of the DHCP daemon that is currently running
echo pidofproc /usr/sbin/dhcpd
pidofproc /usr/sbin/dhcpd

# stop the dhcpd daemon (no harm if it's not running)
echo "/etc/init.d/dhcpd stop"
/etc/init.d/dhcpd stop
killall -9 dhcpd

# Make sure the leases file is there before we try to start
if [ ! -e /var/lib/dhcp/db/dhcpd.leases ]; then
    touch /var/lib/dhcp/db/dhcpd.leases
fi

# start the dhcpd daemon
echo "/usr/sbin/dhcpd -d -f"
#/usr/sbin/dhcpd  >/dev/null 2>&1 &
/usr/sbin/dhcpd  &

# Dump out the process id of the DHCP daemon that we just started
echo pidofproc /usr/sbin/dhcpd
pidofproc /usr/sbin/dhcpd
