#!/bin/bash
#
# wdmd - watchdog multiplexing daemon
# helper to load the softdog module if a watchdog is not enabled
#

exec="/usr/sbin/wdmd"

watchdog_probe() {
	$exec --probe > /dev/null 2>&1
	retval=$?
	return $retval
}

watchdog_check() {
	watchdog_probe
	retval=$?

	if [ $retval -ne 0 ]; then
		echo -n $"Loading the softdog kernel module: "
		modprobe softdog
		# handle delay in udev setting permission/label
		udevadm settle

		watchdog_probe
		retval=$?
		if [ $retval -ne 0 ]; then
			echo "failed"
			return 1
		fi
		echo "success"
		return 0
	fi
}

case "$1" in
	watchdog-check)
		watchdog_check
		;;
	*)
		echo $"Usage $0 watchdog-check"
		exit 2
esac
exit $?
