From e4fd97e0cb7103403478333537020b02fc9006c9 Mon Sep 17 00:00:00 2001 From: hjr <> Date: Sun, 24 Dec 2017 15:12:36 +0000 Subject: [PATCH] contrib/fhem_watchdog.sh: Simple watchdog solution to monitor fhem on Linux. git-svn-id: https://svn.fhem.de/fhem/trunk@15681 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/contrib/fhem_watchdog.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 fhem/contrib/fhem_watchdog.sh diff --git a/fhem/contrib/fhem_watchdog.sh b/fhem/contrib/fhem_watchdog.sh new file mode 100644 index 000000000..837aff3d5 --- /dev/null +++ b/fhem/contrib/fhem_watchdog.sh @@ -0,0 +1,32 @@ +#!/bin/sh +# +# $Id$ +# +# Simple watchdog solution to monitor and restart fhem on Linux. +# +# Add this define to the fhem configuration: +# define at_FhemPulse at +*00:10 {system("/bin/date +%s > /opt/fhem/log/fhem_pulse.log")} +# +# Add a cron job that runs every ten minutes -> crontab -e +# */10 * * * * /opt/fhem/contrib/fhem_watchdog.sh + + +LOGFILE="/opt/fhem/log/fhem_pulse.log" + +if [ `systemctl status fhem|grep inactive|wc -l` -eq "0" ]; then + # fhem service was started + + if [ ! -e "${LOGFILE}" ]; then + # There is no pulse log file + systemctl restart fhem + exit 0 + fi + if [ $(expr $(/bin/date +%s) - $(cat ${LOGFILE})) -gt 900 ]; then + # Last pulse is older than 15min. + systemctl restart fhem + exit 0 + fi +fi + +exit 0 +