#!/sbin/openrc-run
#
# OpenRC init script for the ISC DHCP relay.
# Based on the former SysV /etc/init.d/isc-dhcp-relay script.
#

description="ISC DHCP relay daemon"

PATH=/sbin:/bin:/usr/sbin:/usr/bin

command="/usr/sbin/dhcrelay"
pidfile="/var/run/dhcrelay.pid"

depend() {
	need net localmount
	use logger
}

_read_config() {
	[ -f /etc/default/isc-dhcp-relay ] || {
		eerror "/etc/default/isc-dhcp-relay does not exist"
		eerror "Run 'dpkg-reconfigure isc-dhcp-relay' to fix the problem."
		return 1
	}
	. /etc/default/isc-dhcp-relay
}

start() {
	local ifcmd="" i

	[ -x "$command" ] || return 0
	_read_config || return 1

	if [ -n "$INTERFACES" ]; then
		for i in $INTERFACES; do
			ifcmd="${ifcmd}-i ${i} "
		done
	fi

	ebegin "Starting ${RC_SVCNAME}"
	start-stop-daemon -S -q -p "$pidfile" \
		-x "$command" -- -q $OPTIONS $ifcmd $SERVERS
	eend $?
}

stop() {
	[ -x "$command" ] || return 0
	ebegin "Stopping ${RC_SVCNAME}"
	start-stop-daemon -K -q -p "$pidfile"
	eend $?
}

status() {
	[ -e "$pidfile" ]
}
