From 5759e2aac6ac26b5ad4f08d1378a71ce5dbdf690 Mon Sep 17 00:00:00 2001
From: Stefan Laudemann <thisco@webcake.de>
Date: Sun, 16 Nov 2014 15:19:18 +0100
Subject: [PATCH] Adds process-watchdog for A.L.F.R.E.D.

Monitors whether or not the A.L.F.R.E.D. is still running on a node or
not. Version 2013.x crashes from time to time and thus some nodes dis-
appear from the map. It is thus suitable to monitor the state of the
daemon on the node itself by periodically making requests to avoid un-
necessary support-requests and manual restarts of these nodes. In a
failure state, the daemon can simply be restarted by triggering its
init-script.

Please note that the bug is most likely gone in v2014.1 and newer and
and thus the package does not need to be included in the firmware in
newer firmwares.
---
 ffpb/ffpb-alfred-watchdog/Makefile            | 46 +++++++++++++++++++
 .../files/bin/ffpb-alfred-watchdog            | 20 ++++++++
 .../files/lib/gluon/cron/ffpb-alfred-watchdog |  1 +
 3 files changed, 67 insertions(+)
 create mode 100644 ffpb/ffpb-alfred-watchdog/Makefile
 create mode 100755 ffpb/ffpb-alfred-watchdog/files/bin/ffpb-alfred-watchdog
 create mode 100644 ffpb/ffpb-alfred-watchdog/files/lib/gluon/cron/ffpb-alfred-watchdog

diff --git a/ffpb/ffpb-alfred-watchdog/Makefile b/ffpb/ffpb-alfred-watchdog/Makefile
new file mode 100644
index 0000000..4227ca4
--- /dev/null
+++ b/ffpb/ffpb-alfred-watchdog/Makefile
@@ -0,0 +1,46 @@
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=ffpb-alfred-watchdog
+PKG_VERSION:=1
+PKG_RELEASE:=$(GLUON_VERSION).$(GLUON_SITE_CODE)-$(GLUON_RELEASE).$(GLUON_CONFIG_VERSION)
+
+PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/ffpb-alfred-watchdog
+  SECTION:=ffpb
+  CATEGORY:=workarounds
+  TITLE:=A.L.F.R.E.D. crash watchdog
+  DEPENDS:=+busybox
+endef
+
+define Package/ffpb-alfred-watchdog/description
+	Monitors whether or not the A.L.F.R.E.D. is still running on a node or
+	not. Version 2013.x crashes from time to time and thus some nodes dis-
+	appear from the map. It is thus suitable to monitor the state of the
+	daemon on the node itself by periodically making requests to avoid un-
+	necessary support-requests and manual restarts of these nodes. In a
+	failure state, the daemon can simply be restarted by triggering its
+	init-script.
+
+	Please note that the bug is most likely gone in v2014.1 and newer and
+	and thus the package does not need to be included in the firmware in
+	newer firmwares.
+endef
+
+define Build/Prepare
+	mkdir -p $(PKG_BUILD_DIR)
+endef
+
+define Build/Configure
+endef
+
+define Build/Compile
+endef
+
+define Package/ffpb-alfred-watchdog/install
+	$(CP) ./files/* $(1)/
+endef
+
+$(eval $(call BuildPackage,ffpb-alfred-watchdog))
diff --git a/ffpb/ffpb-alfred-watchdog/files/bin/ffpb-alfred-watchdog b/ffpb/ffpb-alfred-watchdog/files/bin/ffpb-alfred-watchdog
new file mode 100755
index 0000000..20f5480
--- /dev/null
+++ b/ffpb/ffpb-alfred-watchdog/files/bin/ffpb-alfred-watchdog
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+LOCK_FILE="/tmp/.alfred_watchdog_lock"
+
+[[ -e ${LOCK_FILE} ]] && exit 0;
+
+/bin/touch ${LOCK_FILE}
+
+rand=`tr -cd 0-9 </dev/urandom | head -c 32`
+delay=`expr ${rand} % 55`
+sleep ${delay}m
+                                                
+/usr/sbin/alfred -b bat0 -r 158 > /dev/null 2&>1
+if [[ "$?" == 255 ]] ; then                                                                                      
+    logger -s -t ffpb-alfred-watchdog -p local0.info "A.L.F.R.E.D. appears to be dead. Triggering a restart now."
+    /etc/init.d/alfred restart > /dev/null 2&>1
+fi
+                                             
+[[ -e ${LOCK_FILE} ]] && /bin/rm ${LOCK_FILE}
+
diff --git a/ffpb/ffpb-alfred-watchdog/files/lib/gluon/cron/ffpb-alfred-watchdog b/ffpb/ffpb-alfred-watchdog/files/lib/gluon/cron/ffpb-alfred-watchdog
new file mode 100644
index 0000000..256531b
--- /dev/null
+++ b/ffpb/ffpb-alfred-watchdog/files/lib/gluon/cron/ffpb-alfred-watchdog
@@ -0,0 +1 @@
+55 * * * * /bin/ffpb-alfred-watchdog
-- 
GitLab