From a6e07d780ccead52bf9e6674437e2d621721f6fb Mon Sep 17 00:00:00 2001
From: FFS-Roland <ffs-monitor@gmx.de>
Date: Sun, 27 Aug 2017 15:20:04 +0200
Subject: [PATCH] new Package ffs-watchdog for rebooting hanging nodes.

---
 ffs-watchdog/Makefile                         | 38 +++++++++++++++++++
 ffs-watchdog/files/etc/init.d/ffs-watchdog    | 12 ++++++
 .../files/usr/lib/micron.d/ffs-watchdog       |  1 +
 ffs-watchdog/files/usr/sbin/ffs-watchdog      | 28 ++++++++++++++
 ffs-watchdog/ipkg/postinst                    |  3 ++
 5 files changed, 82 insertions(+)
 create mode 100644 ffs-watchdog/Makefile
 create mode 100755 ffs-watchdog/files/etc/init.d/ffs-watchdog
 create mode 100644 ffs-watchdog/files/usr/lib/micron.d/ffs-watchdog
 create mode 100755 ffs-watchdog/files/usr/sbin/ffs-watchdog
 create mode 100644 ffs-watchdog/ipkg/postinst

diff --git a/ffs-watchdog/Makefile b/ffs-watchdog/Makefile
new file mode 100644
index 0000000..2e13831
--- /dev/null
+++ b/ffs-watchdog/Makefile
@@ -0,0 +1,38 @@
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=ffs-watchdog
+PKG_VERSION:=1
+
+PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
+
+include $(GLUONDIR)/include/package.mk
+
+PKG_CONFIG_DEPENDS += $(GLUON_I18N_CONFIG)
+
+
+define Package/ffs-watchdog
+  SECTION:=gluon
+  CATEGORY:=Gluon
+  TITLE:=Checking Node running correctly
+endef
+
+define Build/Prepare
+	mkdir -p $(PKG_BUILD_DIR)
+endef
+
+define Build/Configure
+endef
+
+define Build/Compile
+endef
+
+define Package/ffs-watchdog/install
+	$(INSTALL_DIR) $(1)/etc/init.d
+	$(INSTALL_BIN) ./files/etc/init.d/ffs-watchdog $(1)/etc/init.d/ffs-watchdog
+	$(INSTALL_DIR) $(1)/usr/sbin
+	$(INSTALL_BIN) ./files/usr/sbin/ffs-watchdog $(1)/usr/sbin/ffs-watchdog
+	$(INSTALL_DIR) $(1)/usr/lib/micron.d
+	$(INSTALL_BIN) ./files/usr/lib/micron.d/ffs-watchdog $(1)/usr/lib/micron.d/ffs-watchdog
+endef
+
+$(eval $(call BuildPackage,ffs-watchdog))
diff --git a/ffs-watchdog/files/etc/init.d/ffs-watchdog b/ffs-watchdog/files/etc/init.d/ffs-watchdog
new file mode 100755
index 0000000..6524eb8
--- /dev/null
+++ b/ffs-watchdog/files/etc/init.d/ffs-watchdog
@@ -0,0 +1,12 @@
+#!/bin/sh /etc/rc.common
+
+START=97
+
+start () {
+    /etc/init.d/micrond enable
+    /etc/init.d/micrond restart    
+}
+
+stop() {
+    true
+}
diff --git a/ffs-watchdog/files/usr/lib/micron.d/ffs-watchdog b/ffs-watchdog/files/usr/lib/micron.d/ffs-watchdog
new file mode 100644
index 0000000..298d467
--- /dev/null
+++ b/ffs-watchdog/files/usr/lib/micron.d/ffs-watchdog
@@ -0,0 +1 @@
+*/5 * * * * /usr/sbin/ffs-watchdog
diff --git a/ffs-watchdog/files/usr/sbin/ffs-watchdog b/ffs-watchdog/files/usr/sbin/ffs-watchdog
new file mode 100755
index 0000000..3046f66
--- /dev/null
+++ b/ffs-watchdog/files/usr/sbin/ffs-watchdog
@@ -0,0 +1,28 @@
+#!/bin/sh
+ME=$(basename $0)
+if [ $(ps | grep -c "$ME") -gt 4 ]; then
+  logger -s -t $ME "started twice"
+  exit 1
+fi
+
+if [ "$(uci get gluon-setup-mode.@setup_mode[0].enabled)" = "0" ]; then
+  FFS=/tmp/.gw.ffs
+  NOW=$(date +%s)
+  if [ -n "$(batctl gwl | grep '=>')" ]; then
+    echo $NOW >$FFS
+    logger -t $ME "node is online"
+  else
+    if [ -f $FFS ]; then
+      OFF=$(cat $FFS)
+      DELTA=$((NOW - OFF))
+      logger -t $ME "offline for ${DELTA} sec."
+
+      if [ $DELTA -gt 1000 ]; then
+        rm $FFS
+        reboot
+      fi
+    else
+      echo $NOW >$FFS
+    fi
+  fi
+fi
diff --git a/ffs-watchdog/ipkg/postinst b/ffs-watchdog/ipkg/postinst
new file mode 100644
index 0000000..c7ee7b6
--- /dev/null
+++ b/ffs-watchdog/ipkg/postinst
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+/etc/init.d/ffs-watchdog enable
-- 
GitLab