#!/bin/sh
#
# dhcrelay6      This shell script takes care of starting and stopping
#               dhcrelay (DHCPv6).
#
# chkconfig: - 65 35
# description: \
#	The Internet Software Consortium DHCPv6 Relay Agent, dhcrelay, provides a \
#	means for relaying DHCPv6 and BOOTP requests from a subnet to which no \
#	DHCPv6 server is directly connected to one or more DHCPv6 servers on other \
#	subnets.
#
# processname: dhcrelay
# pidfile: /var/run/dhcrelay6.pid

WITHOUT_RC_COMPAT=1

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

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

PIDFILE=/var/run/dhcrelay6.pid
LOCKFILE=/var/lock/subsys/dhcrelay6

# Source config.
SourceIfNotEmpty /etc/sysconfig/dhcrelay6

RETVAL=0
DISPLAYNAME="dhcrelay (DHCPv6)"

start()
{
	# Check that networking is on.
	is_yes "$NETWORKING" || return 0

	if [ -z "$LOWER_INTERFACES" -o -z "$UPPER_INTERFACES" ]; then
		msg_starting "$DISPLAYNAME"
		printf "%s" "At least one lower and one upper network interface must be specified"
		echo_failure
		echo
		return 1
	fi

	export UPPER_INTERFACES LOWER_INTERFACES OPTIONS
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user dhcrelay6 \
		--displayname "$DISPLAYNAME" -- dhcrelay6
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user dhcrelay6 \
		--displayname "$DISPLAYNAME" -- dhcrelay
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload|restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condreload|condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	status)
		status --pidfile "$PIDFILE" --expect-user dhcrelay6 --displayname "dhcrelay (DHCPv6)" -- dhcrelay
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|restart|condstop|condrestart|status}"
		RETVAL=1
esac

exit $RETVAL
