xref: /freebsd/libexec/rc/rc.d/watchdogd (revision f99f0ee14e3af81c23150a6a340259ca8a33d01a)
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#
280696600cSBjoern A. Zeeb
290696600cSBjoern A. Zeeb# PROVIDE: watchdogd
300696600cSBjoern A. Zeeb# REQUIRE: FILESYSTEMS syslogd
310696600cSBjoern A. Zeeb# KEYWORD: nojail shutdown
320696600cSBjoern A. Zeeb
330696600cSBjoern A. Zeeb. /etc/rc.subr
340696600cSBjoern A. Zeeb
350696600cSBjoern A. Zeebname="watchdogd"
360696600cSBjoern A. Zeebdesc="Watchdog daemon"
370696600cSBjoern A. Zeebrcvar="watchdogd_enable"
380696600cSBjoern A. Zeebcommand="/usr/sbin/${name}"
390696600cSBjoern A. Zeebpidfile="/var/run/${name}.pid"
405fda0d60SAndriy Gaponstart_precmd="watchdogd_prestart"
415fda0d60SAndriy Gaponstop_precmd="watchdogd_prestop"
425fda0d60SAndriy Gaponstop_postcmd="watchdogd_poststop"
435fda0d60SAndriy Gaponwatchdog_command="/usr/sbin/watchdog"
445fda0d60SAndriy Gapon
455fda0d60SAndriy Gaponwatchdogd_prestart()
465fda0d60SAndriy Gapon{
475fda0d60SAndriy Gapon	if [ -n "${watchdogd_timeout}" ] ; then
485fda0d60SAndriy Gapon		rc_flags="${rc_flags} -t ${watchdogd_timeout}"
495fda0d60SAndriy Gapon	fi
505fda0d60SAndriy Gapon	if [ -n "$watchdogd_shutdown_timeout" ] ; then
515fda0d60SAndriy Gapon		rc_flags="${rc_flags} -x ${watchdogd_shutdown_timeout}"
525fda0d60SAndriy Gapon	fi
535fda0d60SAndriy Gapon	return 0
545fda0d60SAndriy Gapon}
555fda0d60SAndriy Gapon
565fda0d60SAndriy Gaponwatchdogd_prestop()
575fda0d60SAndriy Gapon{
585fda0d60SAndriy Gapon	sig_stop="${watchdogd_sig_stop:-TERM}"
595fda0d60SAndriy Gapon}
605fda0d60SAndriy Gapon
615fda0d60SAndriy Gaponwatchdogd_poststop()
625fda0d60SAndriy Gapon{
635fda0d60SAndriy Gapon	if [ ${watchdogd_shutdown_timeout:-0} -gt 0 ] ; then
645fda0d60SAndriy Gapon		case "${rc_shutdown}" in
655fda0d60SAndriy Gapon		"reboot")
665fda0d60SAndriy Gapon			info "watchdog timer is set to" \
675fda0d60SAndriy Gapon				${watchdogd_shutdown_timeout} "before shutdown"
685fda0d60SAndriy Gapon			return 0
695fda0d60SAndriy Gapon			;;
705fda0d60SAndriy Gapon		"single")
715fda0d60SAndriy Gapon			info "watchdog timer is disabled before going to" \
725fda0d60SAndriy Gapon				"single user mode"
735fda0d60SAndriy Gapon			${watchdog_command} -t 0
745fda0d60SAndriy Gapon			;;
755fda0d60SAndriy Gapon		"")
765fda0d60SAndriy Gapon			info "watchdog timer is disabled after administrative" \
775fda0d60SAndriy Gapon				"${name} stop"
785fda0d60SAndriy Gapon			${watchdog_command} -t 0
795fda0d60SAndriy Gapon			;;
805fda0d60SAndriy Gapon		*)
815fda0d60SAndriy Gapon			warn "unknown shutdown mode '${rc_shutdown}'"
825fda0d60SAndriy Gapon			warn "watchdog timer is set to ${watchdogd_shutdown_timeout}"
835fda0d60SAndriy Gapon			return 0
845fda0d60SAndriy Gapon			;;
855fda0d60SAndriy Gapon		esac
865fda0d60SAndriy Gapon	fi
875fda0d60SAndriy Gapon	return 0
885fda0d60SAndriy Gapon}
890696600cSBjoern A. Zeeb
900696600cSBjoern A. Zeebload_rc_config $name
91*f99f0ee1SAlexander Leidinger
92*f99f0ee1SAlexander Leidinger# doesn't make sense to run in a svcj: privileged operations
93*f99f0ee1SAlexander Leidingerwatchdogd_svcj="NO"
94*f99f0ee1SAlexander Leidinger
950696600cSBjoern A. Zeebrun_rc_command "$1"
96