#!/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)
		# samba's init starts this too, so a second call must do nothing
		pidof wsdd2 > /dev/null && exit 0
		$DAEMON -d > /dev/null 2>&1
		;;
	stop)
		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
