#!/bin/sh
# DHCP relay agent
#
# chkconfig:	345 80 20
# description:	DHCP relay agent

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

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

# Demon specified configuration.
. /etc/sysconfig/dhcp-relay

# Check that networking is up.
if is_no "${NETWORKING}"; then
	msg_Network_Down "DHCP realay"
	exit 1
fi

if [ -n "DHCP_REALY_INTERFACES" ]; then
	OPTIONS="-i $DHCP_REALY_INTERFACES"
fi


# See how we were called.
case "$1" in
  start)
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/dhcp-relay ]; then
		msg_starting "DHCP relay"
		daemon dhcrelay $OPTIONS $DHCP_SERVERS_IP
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/dhcp-relay
	else
		msg_Already_Running "DHCP relay"
		exit 1
	fi
	;;
  stop)
	msg_stopping "DHCP relay"
	killproc dhcrelay
	rm -f /var/lock/subsys/dhcp-relay
	;;
  restart|reload)
	$0 stop
	$0 start
	;;
  status)
	status dhcrelay
	;;
  *)
	msg_Usage "$0 {start|stop|restart|reload|status}"
	exit 1
esac

exit $RETVAL
