#! /bin/sh

. /etc/init.d/functions.sh
. /etc/conf.d/ipsetd

NAME=ipsetd
DESC=$NAME
DAEMON=/sbin/$NAME

SSD=start-stop-daemon

start_ipsetd () {
	if [ "$ARPPING_IPADDRESS_ENABLED" = yes ]; then
		$SSD --start --exec $DAEMON --nicelevel -2 -- $IPSETD_OPTIONS
	else
		information "$DESC disabled"
	fi
}

stop_ipsetd () {
	$SSD --stop --oknodo --retry 5 --exec $DAEMON
}

case "$1" in
	start)
		begin "Starting $DESC"
		start_ipsetd
		end $?
		;;
	stop)
		begin "Stopping $DESC"
		stop_ipsetd
		end $?
		;;
	restart)
		begin "Starting $DESC"
		stop_ipsetd && start_ipsetd
		end $?
		;;
	*)
		error "Usage: $0 start|stop|restart"
		;;
esac

exit 0
