#!/bin/sh
# Discovery start-up script.

APP_NAME="discoverd"
APP_BIN="/usr/bin/${APP_NAME}"
APP_OPTS=""
APP_PID_FILE="/var/run/${APP_NAME}.pid"

WD_BIN="barix-wd"


start() {
	# Just defer to start_wd().
	echo "${APP_NAME}: Starting the ${APP_NAME} application..."
	${WD_BIN} --pid-file=${APP_PID_FILE} --timeout=5 --background --start -- ${APP_BIN} ${APP_OPTS}
	echo "${APP_NAME}: Starting the ${APP_NAME} application...DONE"
}

stop() {
	# Just defer to stop_wd().
	echo "${APP_NAME}: Stopping the ${APP_NAME} application..."
	${WD_BIN} --pid-file=${APP_PID_FILE} --stop --wait
	echo "${APP_NAME}: Stopping the ${APP_NAME} application...DONE"
}

restart() {
	stop
	start
}


case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart|reload)
		restart
		;;
	*)
		echo "Usage: $0 {start|stop|restart}"
		exit 1
esac

exit 0
