#!/bin/sh
#
# nifd	Starts the nifd Daemon
#
# chkconfig:	345 33 67
#
# description:	This is a daemon which runs on Howl clients to monitor the \
#               state of a network interface.  nifd must be running on \
#               systems that use autoipd and mDNSResponder to automatically \
#               obtain a Link-Local IPv4 address and do Zeroconf service \
#               discovery. nifd should not be running otherwise.
#


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

# Get network config
. /etc/sysconfig/network

# Check that networking is up.
if is_yes "${NETWORKING}"; then
	if [ ! -f /var/lock/subsys/network ]; then
		msg_network_down "nifd"
		exit 1
	fi
else
	exit 0
fi

start() {
	# Check if the service is already running?
	if [ -f /var/lock/subsys/nifd ]; then
		msg_already_running "nifd"
		return
	fi

	msg_starting "nifd"
	daemon nifd
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/nifd
}

stop() {
	if [ ! -f /var/lock/subsys/nifd ]; then
		msg_not_running "nifd"
		return
	fi

	msg_stopping "nifd"
	killproc nifd
	rm -f /var/lock/subsys/nifd
}

condrestart() {
	if [ ! -f /var/lock/subsys/nifd ]; then
		msg_not_running "nifd"
		RETVAL=$1
		return
	fi

	stop
	start
}

reload() {
	if [ ! -f /var/lock/subsys/nifd ]; then
		msg_not_running "nifd"
		RETVAL=7
		return
	fi

	msg_reloading "nifd"
	killproc nifd -HUP
	RETVAL=$?
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	stop
	start
	;;
  try-restart)
	condrestart 0
	;;
  reload|force-reload)
	reload
	;;
  status)
	status nifd
	RETVAL=$?
	;;
  *)
	msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}"
	exit 3
esac

exit $RETVAL
