#!/bin/sh
### BEGIN INIT INFO
# Provides:          wsdd2
# Required-Start:    $network $remote_fs
# Required-Stop:     $network $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: WSD/LLMNR Discovery/Name Service Daemon
### END INIT INFO

DAEMON=/usr/sbin/wsdd2

case "$1" in
	start)
		# -d forks off a child, but only after it bound its sockets. Give samba
		# a moment and keep that wait out of the boot.
		( sleep 5; $DAEMON -d > /dev/null 2>&1 ) &
		;;
	stop)
		# the old script left an extra instance behind on every runlevel change
		for pid in $(pidof wsdd2); do
			kill -TERM $pid 2>/dev/null
		done
		i=0
		while [ $i -lt 5 ] && pidof wsdd2 > /dev/null; do
			sleep 1
			i=$(($i + 1))
		done
		for pid in $(pidof wsdd2); do
			kill -KILL $pid 2>/dev/null
		done
		;;
	restart|force-reload)
		$0 stop
		sleep 1
		$0 start
		;;
	*)
		echo "Usage: $0 {start|stop|restart|force-reload}"
		exit 1
		;;
esac
exit 0
