#!/bin/sh
#
# avahi-daemon:       Starts the Avahi dns configuration daemon
#
# chkconfig: - 55 01
# description: avahi-dnsconfd connects to a running avahi-daemon and runs  the  script
#       /etc/avahi/dnsconf.action for each unicast DNS server that is announced
#       on the local LAN. This is useful for configuring unicast DNS servers in
#       a DHCP-like fashion with mDNS.
# processname: avahi-dnsconfd
# config: 


WITHOUT_RC_COMPAT=1

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

RETVAL=0
DAEMON=/usr/sbin/avahi-dnsconfd
LOCKFILE=/var/lock/subsys/avahi-dnsconfd
WRKUSER=root
ARGS_START=" -D"
ARGS_STOP=" -k"
ARGS_RELOAD=" -r"

start() {
    msg_starting $"Avahi mDNS/DNS-SD DNS server configuration"
    start_daemon \
	--lockfile "$LOCKFILE" \
	--no-announce \
	--expect-user root \
	-- $DAEMON $ARGS_START
    RETVAL=$?
    return $RETVAL
}

stop() {
    msg_stopping $"Avahi mDNS/DNS-SD DNS server configuration"
        stop_daemon \
        --lockfile "$LOCKFILE" \
	--no-announce \
        --expect-user $WRKUSER \
        -- $DAEMON
    RETVAL=$?
    return $RETVAL
}

reload() {
	action "Reloading Avahi mDNS/DNS-SD DNS server configuration service:" $DAEMON $ARGS_RELOAD
	echo
	return $RETVAL
}

restart() {
    stop
    sleep 1
    start
}

case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    restart)
	restart
	;;
    reload)
	reload
	;;
    status)
	status --expect-user $WRKUSER -- $DAEMON
	RETVAL=$?
	;;
    condstart)
	if ! [ -f "$LOCKFILE" ]; then
	    start
	fi
	;;
    condstop)
	if [ -f "$LOCKFILE" ]; then
	    stop
	fi
	;;
    condrestart)
	if [ -f "$LOCKFILE" ]; then
	    restart
	fi
	;;
    *)
	msg_usage "${0##*/} {start|stop|status|restart|reload|condstart|condstop|condrestart}"
	RETVAL=1
	;;
esac
exit $RETVAL
