[RFC PATCH] fff-autorestart: Add autorestart package

Adrian Schmutzler freifunk at adrianschmutzler.de
So Jul 2 23:10:19 CEST 2017


This package implements an auto-restart if the router is not able
to connect to a gateway for more than one hour. If there was an
error or crash causing the interruption, it may be resolved by
the restart while no harm is done.

This is an RFC patch, as I'm interested in implementing this into
the firmware of the routers I administer. Thus, any comments,
suggestions and so forth are welcome!

Signed-off-by: Adrian Schmutzler <freifunk at adrianschmutzler.de>
---
 src/packages/fff/fff-autorestart/Makefile          | 40 ++++++++++++++++++++++
 .../files/usr/lib/micron.d/fff-autorestart         |  1 +
 .../fff-autorestart/files/usr/sbin/offlinerestart  | 39 +++++++++++++++++++++
 src/packages/fff/fff/Makefile                      |  1 +
 4 files changed, 81 insertions(+)
 create mode 100755 src/packages/fff/fff-autorestart/Makefile
 create mode 100644 src/packages/fff/fff-autorestart/files/usr/lib/micron.d/fff-autorestart
 create mode 100755 src/packages/fff/fff-autorestart/files/usr/sbin/offlinerestart
 mode change 100644 => 100755 src/packages/fff/fff/Makefile

diff --git a/src/packages/fff/fff-autorestart/Makefile b/src/packages/fff/fff-autorestart/Makefile
new file mode 100755
index 0000000..9870c68
--- /dev/null
+++ b/src/packages/fff/fff-autorestart/Makefile
@@ -0,0 +1,40 @@
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=fff-autorestart
+PKG_VERSION:=1
+PKG_RELEASE:=1
+
+PKG_BUILD_DIR:=$(BUILD_DIR)/fff-autorestart
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/fff-autorestart
+    SECTION:=base
+    CATEGORY:=Freifunk
+    TITLE:= Freifunk-Franken Auto-Restart
+    URL:=http://www.freifunk-franken.de
+    DEPENDS:=+micrond +ip +ip-bridge
+endef
+
+define Package/fff-autorestart/description
+    This restarts the router if no connection
+	to gateways is available
+endef
+
+define Build/Prepare
+	echo "all: " > $(PKG_BUILD_DIR)/Makefile
+endef
+
+define Build/Configure
+	# nothing
+endef
+
+define Build/Compile
+	# nothing
+endef
+
+define Package/fff-autorestart/install
+    $(CP) ./files/* $(1)/
+endef
+
+$(eval $(call BuildPackage,fff-autorestart))
diff --git a/src/packages/fff/fff-autorestart/files/usr/lib/micron.d/fff-autorestart b/src/packages/fff/fff-autorestart/files/usr/lib/micron.d/fff-autorestart
new file mode 100644
index 0000000..885b50a
--- /dev/null
+++ b/src/packages/fff/fff-autorestart/files/usr/lib/micron.d/fff-autorestart
@@ -0,0 +1 @@
+*/5 * * * * /usr/sbin/offlinerestart
diff --git a/src/packages/fff/fff-autorestart/files/usr/sbin/offlinerestart b/src/packages/fff/fff-autorestart/files/usr/sbin/offlinerestart
new file mode 100755
index 0000000..8a117c8
--- /dev/null
+++ b/src/packages/fff/fff-autorestart/files/usr/sbin/offlinerestart
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+# At first some Definitions:
+
+UPPER_LIMIT='75' #Above this limit the online SSID will be used
+LOWER_LIMIT='30' #Below this limit the offline SSID will be used
+# In-between these two values the SSID will never be changed to prevent it from toggeling every Minute.
+
+NOW=$(date +%s)
+
+#Is there an active Gateway?
+GATEWAY_TQ=`batctl gwl | grep "^=>" | awk -F'[()]' '{print $2}'| tr -d " "` #Grep the Connection Quality of the Gateway which is currently used
+if [ ! $GATEWAY_TQ ]; #If there is no gateway there will be errors in the following if clauses
+then
+	GATEWAY_TQ=0 #Just an easy way to get an valid value if there is no gateway
+fi
+if [ $GATEWAY_TQ -gt $UPPER_LIMIT ];
+then
+	echo "Gateway TQ is $GATEWAY_TQ node is online"
+	if [ -s /tmp/gatewayoff ] ; then 
+		rm -f /tmp/gatewayoff
+	fi
+fi
+if [ $GATEWAY_TQ -lt $LOWER_LIMIT ];
+then
+	echo "Gateway TQ is $GATEWAY_TQ node is considered offline"
+	if [ ! -s /tmp/gatewayoff ] ; then 
+		echo $NOW > /tmp/gatewayoff
+	fi
+	OFFLINESINCE=$(($(date +%s)-3600))
+	if [ "$(cat /tmp/gatewayoff)" -lt "$OFFLINESINCE" ] ; then
+		#rm -f /tmp/gatewayoff
+		reboot && exit
+	fi
+fi
+if [ $GATEWAY_TQ -ge $LOWER_LIMIT -a $GATEWAY_TQ -le $UPPER_LIMIT ]; #This is just to get a clean run if we are in-between the grace periode
+then
+	echo "TQ is $GATEWAY_TQ, do nothing"
+fi
diff --git a/src/packages/fff/fff/Makefile b/src/packages/fff/fff/Makefile
old mode 100644
new mode 100755
index b039c2d..21ed827
--- a/src/packages/fff/fff/Makefile
+++ b/src/packages/fff/fff/Makefile
@@ -18,6 +18,7 @@ define Package/fff-base
              +ip6tables \
              +odhcp6c \
              +micrond \
+			 +fff-autorestart \
              +fff-nodewatcher \
              +fff-web \
              +fff-uradvd \
-- 
2.7.4



Mehr Informationen über die Mailingliste franken-dev