xref: /freebsd/libexec/rc/rc.d/watchdogd (revision 5fda0d60c1e004d6581f29c006635a51cee81349)
10696600cSBjoern A. Zeeb#!/bin/sh
20696600cSBjoern A. Zeeb
30696600cSBjoern A. Zeeb# Copyright (c) 2003  Sean M. Kelly <smkelly@FreeBSD.org>
40696600cSBjoern A. Zeeb# All rights reserved.
50696600cSBjoern A. Zeeb#
60696600cSBjoern A. Zeeb# Redistribution and use in source and binary forms, with or without
70696600cSBjoern A. Zeeb# modification, are permitted provided that the following conditions
80696600cSBjoern A. Zeeb# are met:
90696600cSBjoern A. Zeeb# 1. Redistributions of source code must retain the above copyright
100696600cSBjoern A. Zeeb#    notice, this list of conditions and the following disclaimer.
110696600cSBjoern A. Zeeb# 2. Redistributions in binary form must reproduce the above copyright
120696600cSBjoern A. Zeeb#    notice, this list of conditions and the following disclaimer in the
130696600cSBjoern A. Zeeb#    documentation and/or other materials provided with the distribution.
140696600cSBjoern A. Zeeb#
150696600cSBjoern A. Zeeb# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
160696600cSBjoern A. Zeeb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
170696600cSBjoern A. Zeeb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
180696600cSBjoern A. Zeeb# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
190696600cSBjoern A. Zeeb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
200696600cSBjoern A. Zeeb# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
210696600cSBjoern A. Zeeb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
220696600cSBjoern A. Zeeb# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
230696600cSBjoern A. Zeeb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
240696600cSBjoern A. Zeeb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
250696600cSBjoern A. Zeeb# SUCH DAMAGE.
260696600cSBjoern A. Zeeb#
270696600cSBjoern A. Zeeb# $FreeBSD$
280696600cSBjoern A. Zeeb#
290696600cSBjoern A. Zeeb
300696600cSBjoern A. Zeeb# PROVIDE: watchdogd
310696600cSBjoern A. Zeeb# REQUIRE: FILESYSTEMS syslogd
320696600cSBjoern A. Zeeb# KEYWORD: nojail shutdown
330696600cSBjoern A. Zeeb
340696600cSBjoern A. Zeeb. /etc/rc.subr
350696600cSBjoern A. Zeeb
360696600cSBjoern A. Zeebname="watchdogd"
370696600cSBjoern A. Zeebdesc="Watchdog daemon"
380696600cSBjoern A. Zeebrcvar="watchdogd_enable"
390696600cSBjoern A. Zeebcommand="/usr/sbin/${name}"
400696600cSBjoern A. Zeebpidfile="/var/run/${name}.pid"
41*5fda0d60SAndriy Gaponstart_precmd="watchdogd_prestart"
42*5fda0d60SAndriy Gaponstop_precmd="watchdogd_prestop"
43*5fda0d60SAndriy Gaponstop_postcmd="watchdogd_poststop"
44*5fda0d60SAndriy Gaponwatchdog_command="/usr/sbin/watchdog"
45*5fda0d60SAndriy Gapon
46*5fda0d60SAndriy Gaponwatchdogd_prestart()
47*5fda0d60SAndriy Gapon{
48*5fda0d60SAndriy Gapon	if [ -n "${watchdogd_timeout}" ] ; then
49*5fda0d60SAndriy Gapon		rc_flags="${rc_flags} -t ${watchdogd_timeout}"
50*5fda0d60SAndriy Gapon	fi
51*5fda0d60SAndriy Gapon	if [ -n "$watchdogd_shutdown_timeout" ] ; then
52*5fda0d60SAndriy Gapon		rc_flags="${rc_flags} -x ${watchdogd_shutdown_timeout}"
53*5fda0d60SAndriy Gapon	fi
54*5fda0d60SAndriy Gapon	return 0
55*5fda0d60SAndriy Gapon}
56*5fda0d60SAndriy Gapon
57*5fda0d60SAndriy Gaponwatchdogd_prestop()
58*5fda0d60SAndriy Gapon{
59*5fda0d60SAndriy Gapon	sig_stop="${watchdogd_sig_stop:-TERM}"
60*5fda0d60SAndriy Gapon}
61*5fda0d60SAndriy Gapon
62*5fda0d60SAndriy Gaponwatchdogd_poststop()
63*5fda0d60SAndriy Gapon{
64*5fda0d60SAndriy Gapon	if [ ${watchdogd_shutdown_timeout:-0} -gt 0 ] ; then
65*5fda0d60SAndriy Gapon		case "${rc_shutdown}" in
66*5fda0d60SAndriy Gapon		"reboot")
67*5fda0d60SAndriy Gapon			info "watchdog timer is set to" \
68*5fda0d60SAndriy Gapon				${watchdogd_shutdown_timeout} "before shutdown"
69*5fda0d60SAndriy Gapon			return 0
70*5fda0d60SAndriy Gapon			;;
71*5fda0d60SAndriy Gapon		"single")
72*5fda0d60SAndriy Gapon			info "watchdog timer is disabled before going to" \
73*5fda0d60SAndriy Gapon				"single user mode"
74*5fda0d60SAndriy Gapon			${watchdog_command} -t 0
75*5fda0d60SAndriy Gapon			;;
76*5fda0d60SAndriy Gapon		"")
77*5fda0d60SAndriy Gapon			info "watchdog timer is disabled after administrative" \
78*5fda0d60SAndriy Gapon				"${name} stop"
79*5fda0d60SAndriy Gapon			${watchdog_command} -t 0
80*5fda0d60SAndriy Gapon			;;
81*5fda0d60SAndriy Gapon		*)
82*5fda0d60SAndriy Gapon			warn "unknown shutdown mode '${rc_shutdown}'"
83*5fda0d60SAndriy Gapon			warn "watchdog timer is set to ${watchdogd_shutdown_timeout}"
84*5fda0d60SAndriy Gapon			return 0
85*5fda0d60SAndriy Gapon			;;
86*5fda0d60SAndriy Gapon		esac
87*5fda0d60SAndriy Gapon	fi
88*5fda0d60SAndriy Gapon	return 0
89*5fda0d60SAndriy Gapon}
900696600cSBjoern A. Zeeb
910696600cSBjoern A. Zeebload_rc_config $name
920696600cSBjoern A. Zeebrun_rc_command "$1"
93