#!/bin/sh
########################################################################
# Begin $rc_base/init.d/dnsdist
#
# Description : dnsdist - A DNS load-balancer and more
#
########################################################################

. /etc/sysconfig/rc
. ${rc_functions}

[ -r "/etc/sysconfig/dnsdist" ] && . /etc/sysconfig/dnsdist

check_config() {
	if ! /usr/bin/dnsdist --check-config >/dev/null; then
		boot_mesg "dnsdist configuration file contains errors" "${FAILURE}"
		echo_failure
		return 1
	fi

	return 0
}

case "${1}" in
	start)
		if ! check_config; then
			exit 1
		fi

		boot_mesg "Starting dnsdist..."

		# Increasing maximum number of open files
		ulimit -n 65536

		# Starting daemon
		/usr/bin/dnsdist --supervised ${ARGS} >/dev/null &
		evaluate_retval
		;;

	stop)
		boot_mesg "Stopping dnsdist..."
		killproc /usr/bin/dnsdist
		;;

	reload)
		if ! check_config; then
			exit 1
		fi

		boot_mesg "Reloading dnsdist..."
		reloadproc /usr/bin/dnsdist
		;;

	restart)
		if ! check_config; then
			exit 1
		fi

		${0} stop
		sleep 1
		${0} start
		;;

	status)
		statusproc /usr/bin/dnsdist
		;;

	*)
		echo "Usage: ${0} {start|stop|reload|restart|status}"
		exit 1
		;;
esac

# End $rc_base/init.d/dnsdist
