#!/bin/bash
#
# VERSION=4
# CHANGES="All watchdog-services in one place."

function log () {
	echo "[init_watchdogs] ${1}"
}

function host_watchdog () {
	case "${1}" in
		start)
			log "Starting watchdog-service for host-system."
			start-stop-daemon -S -b -x /usr/local/sbin/watchdog-service
			;;
		stop)
			log "Stopping watchdog-service for host-system."
			killall -9 watchdog-service
			;;
	esac
}

function bnfos_watchdog () {
	case "${1}" in
		start)
                        log "Starting watchdog-service for BNFOS."
                        /usr/bin/env -i bash -c "/usr/local/php/bnfos_init.php"
			;;
		stop)
                        log "Stopping watchdog-service for BNFOS."
			killall -9 bnfos
			;;
	esac
}

case "${1}" in
	start)
		# host_watchdog ${1}
		bnfos_watchdog ${1}
		;;
	stop)
		# host_watchdog ${1}
		bnfos_watchdog ${1}
		;;
	restart)
		${0} stop
		${0} start
		;;
	*)
		echo "Usage: ${0} {start|stop|restart}" >&2
		exit 1
		;;
esac
