#!/bin/sh
#
# chkconfig: - 20 80
# description: A software watchdog
#
#
# rc file author: Marc Merlin <marcsoft@merlins.org>
#		  Henning P. Schmiedehausen <hps@tanstaafl.de>
#	  Fix by: K. Yamato <kyamato@miraclelinux.com>
#	    - Fix "${VERBOSE}="yes" line without no space characters.
#	    - Default daemon status is set to off in all run levels.
#          - The following settings are moved to /etc/sysconf/watchdog
#             + choice of watchdog or wd_keepalive as a deamon
#             + verbose option
#             + modules loading and unloading commands
#
#
# Note that even though chkconfig says that this should be run at runlevel 1,
# RH by default won't do this, so the RPM applies an ugly patch to 
# /etc/rc.d/init.d/single so that if you go from RL 3 to RL 1, watchdog is
# restarted anyway (if it's not, it can cause the kernel to reboot your machine
# depending on whether your kernel was compiled with CONFIG_WATCHDOG_NOWAYOUT)
#
# I have filed a bug with RH about this, and I hope they will change their
# single script to allow for other scripts to be run in RL 1.
#
# processname: watchdog
# config: /etc/watchdog.conf
# config: /etc/sysconfig/watchdog
#
### BEGIN INIT INFO
# Provides: watchdog
# Default-Start: 2 3 4 5
# Short-Description: Watchdog
# Description: Watchdog.
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

VERBOSE="no"
WD_DAEMON=/usr/sbin/watchdog
if [ -f /etc/sysconfig/watchdog ]; then
    . /etc/sysconfig/watchdog
fi

[ -x ${WD_DAEMON} -a -e /etc/watchdog.conf ] || exit 0


# See how we were called.
case "$1" in
  start)
	gprintf "Starting watchdog daemon: "

	# Load modules
	if [ "x${START_MOD_CMD}" != "x" ]; then
	  ${START_MOD_CMD}
	fi

	if [ "${VERBOSE}" = "yes" ]; then
	    daemon ${WD_DAEMON} -v
	else
	    daemon ${WD_DAEMON}
	fi
	echo
	touch /var/lock/subsys/watchdog
	;;
  stop)
	gprintf "Stopping watchdog daemon: "
	killproc ${WD_DAEMON}

	# Unload modules
	if [ "x${STOP_MOD_CMD}" != "x" ]; then
	  ${STOP_MOD_CMD}
	fi

	rm -f /var/lock/subsys/watchdog
	;;
  status)
	status ${WD_DAEMON}
	;;
  restart|reload)
      $0 stop
      $0 start
	;;
  *)
	gprintf "Usage: watchdog {start|stop|status|restart|reload}\n"
	exit 1
	;;
esac

exit 0
