watchdog: fix init script for sysvinit

The current init script is installed from source with redhat style.
It does not get configuration from /etc/default/watchdog. We should use
debian style init script.

Write our own script just like what wd_keepalive does.
Also, in the init script, we check the existence of /dev/watchdog to
determine whether to start the daemon or not.

(From OE-Core rev: a31f8dd34e8ea34dfb087ed464575aa390ece09b)

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Chen Qi
2018-06-13 15:58:23 +08:00
committed by Richard Purdie
parent 8aee3cce93
commit d200e3196d
3 changed files with 113 additions and 59 deletions

View File

@@ -1,56 +0,0 @@
Signed-off-by: Diego Rondini <diego.ml@zoho.com>
Upstream-Status: Inappropriate
--- watchdog-5.13.orig/redhat/watchdog.init 2014-11-12 17:18:39.125943000 +0100
+++ watchdog-5.13/redhat/watchdog.init 2014-11-12 18:27:36.189943000 +0100
@@ -7,7 +7,7 @@
# Henning P. Schmiedehausen <hps@tanstaafl.de>
# Source function library.
-. /etc/rc.d/init.d/functions
+. /etc/init.d/functions
[ -x /usr/sbin/watchdog -a -e /etc/watchdog.conf ] || exit 0
@@ -23,22 +23,22 @@
start() {
- echo -n $"Starting $prog: "
+ echo -n "Starting $prog: "
if [ -n "$(pidofproc $prog)" ]; then
- echo -n $"$prog: already running"
- echo_failure
+ echo -n "$prog: already running "
+ failure
echo
return 1
fi
if [ "$VERBOSE" = "yes" ]; then
- daemon /usr/sbin/${prog} -v
+ /usr/sbin/${prog} -v
else
- daemon /usr/sbin/${prog}
+ /usr/sbin/${prog}
fi
RETVAL=$?
[ $RETVAL -eq 0 ] && touch $lockfile
- [ $RETVAL -eq 0 ] && echo_success
- [ $RETVAL -ne 0 ] && echo_failure
+ [ $RETVAL -eq 0 ] && success
+ [ $RETVAL -ne 0 ] && failure
echo
return $RETVAL
}
@@ -50,8 +50,10 @@
# and reboot the box.
killproc $prog -TERM
RETVAL=$?
- echo
[ $RETVAL -eq 0 ] && rm -f $lockfile $pidfile
+ [ $RETVAL -eq 0 ] && success
+ [ $RETVAL -ne 0 ] && failure
+ echo
return $RETVAL
}

View File

@@ -0,0 +1,110 @@
#!/bin/sh
#/etc/init.d/watchdog: start watchdog daemon.
### BEGIN INIT INFO
# Provides: watchdog
# Short-Description: Start software watchdog daemon
# Required-Start: $all
# Required-Stop: $all
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO
PATH=/bin:/usr/bin:/sbin:/usr/sbin
test -x /usr/sbin/watchdog || exit 0
# For configuration of the init script use the file
# /etc/default/watchdog, do not edit this init script.
# Set run_watchdog to 1 to start watchdog or 0 to disable it.
run_watchdog=0
# Specify additional watchdog options here (see manpage).
watchdog_options=""
# Specify module to load
watchdog_module="none"
[ -e /etc/default/watchdog ] && . /etc/default/watchdog
NAME=watchdog
DAEMON=/usr/sbin/watchdog
STOP_RETRY_SCHEDULE='TERM/10/forever/KILL/1'
. /etc/init.d/functions
# Mock Debian stuff
log_begin_msg() {
echo -n $*
}
log_end_msg() {
if [ "$1" = "0" ]; then
echo 'done'
else
echo 'error'
fi
}
log_daemon_msg() {
echo $*
}
log_progress_msg() {
echo $*
}
case "$1" in
start)
if [ $run_watchdog = 1 ]
then
# do we have to load a module?
[ "${watchdog_module:-none}" != "none" ] && /sbin/modprobe $watchdog_module
# Check /dev/watchdog here because if it does not exist after module loading,
# it makes no sense to start the daemon
test -e /dev/watchdog || { log_daemon_msg "daemon not start due to lack of /dev/watchdog"; exit 0; }
log_begin_msg "Starting watchdog daemon..."
start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
--exec $DAEMON -- $watchdog_options
log_end_msg $?
fi
;;
stop)
if [ $run_watchdog = 1 ]
then
log_begin_msg "Stopping watchdog daemon..."
start-stop-daemon --stop --quiet --retry $STOP_RETRY_SCHEDULE \
--pidfile /var/run/$NAME.pid
fi
;;
restart)
$0 force-reload
;;
force-reload)
if [ $run_watchdog = 0 ]; then exit 0; fi
log_daemon_msg "Restarting $NAME"
$0 stop
$0 start
;;
status)
status "$DAEMON"
;;
*)
echo "Usage: /etc/init.d/watchdog {start|stop|restart|force-reload|status}"
exit 1
esac
exit 0

View File

@@ -11,7 +11,7 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=ecc0551bf54ad97f6b541720f84d6569"
SRC_URI = "${SOURCEFORGE_MIRROR}/watchdog/watchdog-${PV}.tar.gz \
file://0001-Include-linux-param.h-for-EXEC_PAGESIZE-definition.patch \
file://0001-watchdog-remove-interdependencies-of-watchdog-and-wd.patch \
file://watchdog-init.patch \
file://watchdog.init \
file://wd_keepalive.init \
"
@@ -31,7 +31,7 @@ EXTRA_OECONF += " --disable-nfs "
INITSCRIPT_PACKAGES = "${PN} ${PN}-keepalive"
INITSCRIPT_NAME_${PN} = "watchdog.sh"
INITSCRIPT_NAME_${PN} = "watchdog"
INITSCRIPT_PARAMS_${PN} = "start 25 1 2 3 4 5 . stop 85 0 6 ."
INITSCRIPT_NAME_${PN}-keepalive = "wd_keepalive"
@@ -49,7 +49,7 @@ do_install_append() {
install -m 0644 ${S}/debian/watchdog.service ${D}${systemd_system_unitdir}
install -m 0644 ${S}/debian/wd_keepalive.service ${D}${systemd_system_unitdir}
install -D ${S}/redhat/watchdog.init ${D}/${sysconfdir}/init.d/watchdog.sh
install -Dm 0755 ${WORKDIR}/watchdog.init ${D}/${sysconfdir}/init.d/watchdog
install -Dm 0755 ${WORKDIR}/wd_keepalive.init ${D}${sysconfdir}/init.d/wd_keepalive
# watchdog.conf is provided by the watchdog-config recipe