#! /bin/sh
# dbus event.d script for dhcdbd

# Check the package is still installed
[ -x /sbin/dhcdbd ] || exit 0

# Get LSB functions
. /lib/lsb/init-functions


case "$1" in
    start)
	log_begin_msg "Starting DHCP client manager..."
	start-stop-daemon --start --quiet --exec /sbin/dhcdbd -- --system
	log_end_msg $?
	;;
    stop)
    	log_begin_msg "Stopping DHCP client manager..."
	if [ -e /var/run/dbus/system_bus_socket ]; then
	    /usr/bin/dbus-send --system \
	    		       --dest=com.redhat.dhcp \
			       --type=method_call \
			       --print-reply \
			       --reply-timeout=20000 \
			       /com/redhat/dhcp \
			       com.redhat.dhcp.quit >/dev/null 2>&1
	else
	    start-stop-daemon --stop --quiet --exec /sbin/dhcdbd
	fi
	log_end_msg $?
	;;
    restart)
        $0 stop
        $0 start
	;;
    *)
	echo "Usage: /etc/dbus-1/event.d/dhcdbd {start|stop|restart}"
	exit 1
	;;
esac

exit 0
