#!/bin/sh

. /etc/init.d/functions.sh
. /etc/conf.d/wsd

NAME=wsd
DESC="ONVIF daemon"
DAEMON=/usr/bin/$NAME
CONF=/etc/sysconfig/ws_enabled.conf

start_wsd() {
	start_daemon $DAEMON
}

stop_wsd() {
	stop_daemon $DAEMON
}

conditional_start() {
	local ws_enabled
	ws_enabled=$(sed -rne 's|^Enabled[[:blank:]]*=[[:blank:]]*"?([[:alpha:]]+)"?|\1|p' $CONF)

	if [ "$ws_enabled" = yes ]; then
		start_wsd
	else
		information "Web Services disabled"
	fi
}

case "$1" in
	start)
		begin "Starting $DESC $NAME"
		conditional_start
		end $?
		;;
	stop)
		begin "Stopping $DESC $NAME"
		stop_wsd
		end $?
		;;
	restart)
		begin "Restarting $DESC $NAME"
		stop_wsd && conditional_start
		end $?
		;;
	*)
		error "Usage: $0 start|stop|restart"
		;;
esac

exit 0
