#!/bin/sh
#
# dhcpd This shell script takes care of starting and stopping
# dhcpd.
#
# chkconfig: - 65 35
# description: dhcpd provide access to Dynamic Host Control Protocol.
# Marat "Billy" Bilialov, devel @ socket.ru, http://socket.ru/vlan-howto
# Made of script by  Doug Monroe doug @ planetconnect.com, http://www.planetconnect.com/vlan/
# Mar. 22, 2002

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -f /usr/sbin/dhcpd ] || exit 0
#[ -f /etc/dhcpd.conf ] || exit 0
#[ -f /var/lib/dhcp/dhcpd.leases ] || exit 0

RETVAL=0
prog="dhcpd"

#  ,     /etc/rc.d/init.d/vlan
LIST="eth1 $2" # eth1  

start() {
    echo -n $"Starting $prog: "

    # ,        
    if [ -f /tmp/vlan-dhcpd.conf ]; 
    then
	echo " - started using /tmp/vlan-dhcpd.conf"
	daemon /usr/sbin/dhcpd -cf /tmp/vlan-dhcpd.conf $LIST
    else
    #   ,   .
	echo " - started using /etc/dhcpd.conf"
	daemon /usr/sbin/dhcpd $LIST
    fi
    ##################################################################
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/dhcpd
    return $RETVAL
}

stop() {
    # Stop daemons.
    echo -n $"Shutting down $prog: "
    killproc dhcpd
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/dhcpd
    return $RETVAL
}

# See how we were called.
case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    restart|reload)
	stop
	start
	RETVAL=$?
	;;
    condrestart)
	if [ -f /var/lock/subsys/dhcpd ]; then
	    stop
	    start
	    RETVAL=$?
	fi
	;;
    status)
	status dhcpd
	RETVAL=$?
	;;
    *)
	echo $"Usage: $0 {start|stop|restart|condrestart|status}"
	exit 1
esac

exit $RETVAL
