[v7,6/6] fff-autorestart: Add autorestart package

Submitted by Adrian Schmutzler on Aug. 21, 2017, 4:43 p.m.

Details

Message ID 1503333785-5003-6-git-send-email-freifunk@adrianschmutzler.de
State Superseded
Headers show

Commit Message

Adrian Schmutzler Aug. 21, 2017, 4:43 p.m.
This package implements an auto-restart if the router has not
been able to connect to a gateway for more than 30 minutes. If
there had been an error or crash causing the interruption, it
may be resolved by the restart while no harm is done.

After the second restart, the delay is raised so the third and
subsequent restarts are limited to one per day.

This is a merge of my 3 previous patches introducing the
autorestart capability. Now, the autorestart is disabled by
default.

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
---
 src/packages/fff/fff-autorestart/Makefile          | 40 ++++++++++++++++
 .../files/usr/lib/micron.d/fff-autorestart         |  1 +
 .../files/usr/sbin/disable_autorestart.sh          | 15 ++++++
 .../files/usr/sbin/enable_autorestart.sh           | 15 ++++++
 .../fff-autorestart/files/usr/sbin/offlinerestart  | 53 ++++++++++++++++++++++
 .../fff-web/files/www/ssl/cgi-bin/settings.html    | 15 ++++++
 src/packages/fff/fff/Makefile                      |  1 +
 7 files changed, 140 insertions(+)
 create mode 100644 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/disable_autorestart.sh
 create mode 100755 src/packages/fff/fff-autorestart/files/usr/sbin/enable_autorestart.sh
 create mode 100755 src/packages/fff/fff-autorestart/files/usr/sbin/offlinerestart

Patch hide | download patch | download mbox

diff --git a/src/packages/fff/fff-autorestart/Makefile b/src/packages/fff/fff-autorestart/Makefile
new file mode 100644
index 0000000..8c062e5
--- /dev/null
+++ b/src/packages/fff/fff-autorestart/Makefile
@@ -0,0 +1,40 @@ 
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=fff-autorestart
+PKG_VERSION:=2
+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 +fff-config
+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/disable_autorestart.sh b/src/packages/fff/fff-autorestart/files/usr/sbin/disable_autorestart.sh
new file mode 100755
index 0000000..f83907b
--- /dev/null
+++ b/src/packages/fff/fff-autorestart/files/usr/sbin/disable_autorestart.sh
@@ -0,0 +1,15 @@ 
+#!/bin/sh
+# This disables the auto-restart feature permanently
+# (setting is preserved during upgrades)
+
+uci -q set "fff.autorestart=settings"
+uci -q set "fff.autorestart.enabled=0"
+
+uci -q commit fff
+
+if [ -s /tmp/gatewayoff ] ; then 
+	rm -f /tmp/gatewayoff
+fi
+if [ -s /etc/autorestartcount ] ; then 
+	rm -f /etc/autorestartcount
+fi
diff --git a/src/packages/fff/fff-autorestart/files/usr/sbin/enable_autorestart.sh b/src/packages/fff/fff-autorestart/files/usr/sbin/enable_autorestart.sh
new file mode 100755
index 0000000..4f7c3cb
--- /dev/null
+++ b/src/packages/fff/fff-autorestart/files/usr/sbin/enable_autorestart.sh
@@ -0,0 +1,15 @@ 
+#!/bin/sh
+# This enables the auto-restart feature permanently
+# (setting is preserved during upgrades)
+
+uci -q set "fff.autorestart=settings"
+uci -q set "fff.autorestart.enabled=1"
+
+uci -q commit fff
+
+if [ -s /tmp/gatewayoff ] ; then 
+	rm -f /tmp/gatewayoff
+fi
+if [ -s /etc/autorestartcount ] ; then 
+	rm -f /etc/autorestartcount
+fi
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..5e1ce52
--- /dev/null
+++ b/src/packages/fff/fff-autorestart/files/usr/sbin/offlinerestart
@@ -0,0 +1,53 @@ 
+#!/bin/sh
+
+if [ ! "$(uci -q get fff.autorestart.enabled)" = "1" ] ; then
+	exit 0
+fi
+
+UPPER_LIMIT='50' # Above this limit the gateway will be considered online
+LOWER_LIMIT='20' # Below this limit the gateway will be considered offline
+# In-between these two values the state is not changed
+
+NOW=$(date +%s)
+
+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
+	if [ -s /etc/autorestartcount ] ; then 
+		rm -f /etc/autorestartcount
+	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)-1800)) # Restart after 30 minutes
+	OFFLINEDAY=$(($(date +%s)-86400)) # Restart after 1 day
+	if [ "$(cat /tmp/gatewayoff)" -lt "$OFFLINESINCE" ] ; then
+		if [ -s /etc/autorestartcount ] ; then # Auto-restart has already taken place
+		    restartcount="$(cat /etc/autorestartcount)"
+			if [ "$restartcount" -lt 2 ] || [ "$(cat /tmp/gatewayoff)" -lt "$OFFLINEDAY" ] ; then
+				# 1st and 2nd restart after 30 minutes, 3rd+ restart after one day
+				echo $((restartcount + 1)) > /etc/autorestartcount
+				reboot && exit
+			fi
+		else
+			echo "1" > /etc/autorestartcount
+			reboot && exit
+		fi
+	fi
+fi
+if [ $GATEWAY_TQ -ge $LOWER_LIMIT ] && [ $GATEWAY_TQ -le $UPPER_LIMIT ]; # This is just to get a clean run if we are in-between the grace periode
+then
+	echo "Gateway TQ is $GATEWAY_TQ - Do nothing"
+fi
diff --git a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/settings.html b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/settings.html
index f510431..73e3e59 100755
--- a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/settings.html
+++ b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/settings.html
@@ -64,6 +64,13 @@  if [ "$REQUEST_METHOD" == "POST" ] ; then
 			fi
 		fi
 		
+		uci -q set "fff.autorestart=settings"
+		if [ "$POST_autorestart_enabled" == "on" ] ; then
+			uci -q set "fff.autorestart.enabled=1"
+		else
+			uci -q set "fff.autorestart.enabled=0"
+		fi
+		
 		uci commit
 		MSG='<span class="green">Daten gespeichert! - Bitte Router neustarten.</span>'
 	fi
@@ -89,6 +96,11 @@  if [ "$(uci -q get 'fff.notifyupdate.resetonupgrade')" == "0" ] ; then # not set
 else
 	upgrade_reset_checked="$chkd"
 fi
+if [ "$(uci -q get 'fff.autorestart.enabled')" == "1" ] ; then # not set=0
+	autorestart_checked="$chkd"
+else
+	autorestart_checked=""
+fi
 %>
 <% show_msg %>
 <form method="post">
@@ -145,6 +157,9 @@  fi
 		</td></tr>
 		<% fi %>
 		
+		<tr><th>Auto-restart enabled:</th><td colspan="2">
+			<input type="checkbox" name="autorestart_enabled" <%= ${autorestart_checked} %>/>
+		</td></tr>
 	</table>
 </fieldset>
 </td></tr>
diff --git a/src/packages/fff/fff/Makefile b/src/packages/fff/fff/Makefile
index 594406d..9eaa0cd 100644
--- 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-config \
              +fff-nodewatcher \
              +fff-web \

Comments

Christian Dresel Aug. 24, 2017, 1:07 p.m.
hi

ich hab mir das Script mal angesehen und auf einen Problemrouter
installiert. Scheint soweit zu laufen (zumindest passt die Ausgabe, ob
er auch neu startet wird sich im problemfall dann zeigen...) muss mir
den Code aber nochmal in Ruhe angucken. Eine kleine Anmerkung Inline:

On 21.08.2017 18:43, Adrian Schmutzler wrote:
> This package implements an auto-restart if the router has not
> been able to connect to a gateway for more than 30 minutes. If
> there had been an error or crash causing the interruption, it
> may be resolved by the restart while no harm is done.
> 
> After the second restart, the delay is raised so the third and
> subsequent restarts are limited to one per day.
> 
> This is a merge of my 3 previous patches introducing the
> autorestart capability. Now, the autorestart is disabled by
> default.
> 
> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> ---
>  src/packages/fff/fff-autorestart/Makefile          | 40 ++++++++++++++++
>  .../files/usr/lib/micron.d/fff-autorestart         |  1 +
>  .../files/usr/sbin/disable_autorestart.sh          | 15 ++++++
>  .../files/usr/sbin/enable_autorestart.sh           | 15 ++++++
>  .../fff-autorestart/files/usr/sbin/offlinerestart  | 53 ++++++++++++++++++++++
>  .../fff-web/files/www/ssl/cgi-bin/settings.html    | 15 ++++++
>  src/packages/fff/fff/Makefile                      |  1 +
>  7 files changed, 140 insertions(+)
>  create mode 100644 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/disable_autorestart.sh
>  create mode 100755 src/packages/fff/fff-autorestart/files/usr/sbin/enable_autorestart.sh
>  create mode 100755 src/packages/fff/fff-autorestart/files/usr/sbin/offlinerestart
> 
> diff --git a/src/packages/fff/fff-autorestart/Makefile b/src/packages/fff/fff-autorestart/Makefile
> new file mode 100644
> index 0000000..8c062e5
> --- /dev/null
> +++ b/src/packages/fff/fff-autorestart/Makefile
> @@ -0,0 +1,40 @@
> +include $(TOPDIR)/rules.mk
> +
> +PKG_NAME:=fff-autorestart
> +PKG_VERSION:=2
> +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 +fff-config
> +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/disable_autorestart.sh b/src/packages/fff/fff-autorestart/files/usr/sbin/disable_autorestart.sh
> new file mode 100755
> index 0000000..f83907b
> --- /dev/null
> +++ b/src/packages/fff/fff-autorestart/files/usr/sbin/disable_autorestart.sh
> @@ -0,0 +1,15 @@
> +#!/bin/sh
> +# This disables the auto-restart feature permanently
> +# (setting is preserved during upgrades)
> +
> +uci -q set "fff.autorestart=settings"
> +uci -q set "fff.autorestart.enabled=0"
> +
> +uci -q commit fff
> +
> +if [ -s /tmp/gatewayoff ] ; then 
> +	rm -f /tmp/gatewayoff
> +fi
> +if [ -s /etc/autorestartcount ] ; then 
> +	rm -f /etc/autorestartcount
> +fi
> diff --git a/src/packages/fff/fff-autorestart/files/usr/sbin/enable_autorestart.sh b/src/packages/fff/fff-autorestart/files/usr/sbin/enable_autorestart.sh
> new file mode 100755
> index 0000000..4f7c3cb
> --- /dev/null
> +++ b/src/packages/fff/fff-autorestart/files/usr/sbin/enable_autorestart.sh
> @@ -0,0 +1,15 @@
> +#!/bin/sh
> +# This enables the auto-restart feature permanently
> +# (setting is preserved during upgrades)
> +
> +uci -q set "fff.autorestart=settings"
> +uci -q set "fff.autorestart.enabled=1"
> +
> +uci -q commit fff
> +
> +if [ -s /tmp/gatewayoff ] ; then 
> +	rm -f /tmp/gatewayoff
> +fi
> +if [ -s /etc/autorestartcount ] ; then 
> +	rm -f /etc/autorestartcount
> +fi
> 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..5e1ce52
> --- /dev/null
> +++ b/src/packages/fff/fff-autorestart/files/usr/sbin/offlinerestart
> @@ -0,0 +1,53 @@
> +#!/bin/sh
> +
> +if [ ! "$(uci -q get fff.autorestart.enabled)" = "1" ] ; then
> +	exit 0
> +fi
> +
> +UPPER_LIMIT='50' # Above this limit the gateway will be considered online
> +LOWER_LIMIT='20' # Below this limit the gateway will be considered offline
> +# In-between these two values the state is not changed
> +
> +NOW=$(date +%s)
> +
> +GATEWAY_TQ=$(batctl gwl | grep "^=>" | awk -F'[()]' '{print $2}'| tr -d " ") # Grep the connection quality of the gateway which is currently used

ich verwende bei mir Batman 2016.5 (dezentrale Hood und so) und da kommt
kein => mehr drinnen vor (oder liegt es daran, das ich nur ein Gateway
habe?!). Die Ausgabe sieht bei mir etwas anders aus:

root@EG1:~# batctl gwl
[B.A.T.M.A.N. adv 2016.5, MainIF/MAC: eth1.3/f4:f2:6d:9c:8c:c0
(bat0/86:26:0e:e5:77:3e BATMAN_IV)]
  Router            ( TQ) Next Hop          [outgoingIf]  Bandwidth
* 66:66:b3:de:f5:cd (205) 68:72:51:6a:8e:8f [    w2mesh]: 10.0/2.0 MBit

Ich hab das ganze nun ein klein wenig geändert:

root@EG1:~# batctl gwl | grep "*" | awk -F'[()]' '{print $2}'| tr -d " "
216

sollte diese Anpassung auch unter 2013.4 mit mehreren GWs gehen, würde
ich vorschlagen dies so zu übernehmen (außer jemand fällt noch was
besseres ein)

mfg

Christian


> +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
> +	if [ -s /etc/autorestartcount ] ; then 
> +		rm -f /etc/autorestartcount
> +	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)-1800)) # Restart after 30 minutes
> +	OFFLINEDAY=$(($(date +%s)-86400)) # Restart after 1 day
> +	if [ "$(cat /tmp/gatewayoff)" -lt "$OFFLINESINCE" ] ; then
> +		if [ -s /etc/autorestartcount ] ; then # Auto-restart has already taken place
> +		    restartcount="$(cat /etc/autorestartcount)"
> +			if [ "$restartcount" -lt 2 ] || [ "$(cat /tmp/gatewayoff)" -lt "$OFFLINEDAY" ] ; then
> +				# 1st and 2nd restart after 30 minutes, 3rd+ restart after one day
> +				echo $((restartcount + 1)) > /etc/autorestartcount
> +				reboot && exit
> +			fi
> +		else
> +			echo "1" > /etc/autorestartcount
> +			reboot && exit
> +		fi
> +	fi
> +fi
> +if [ $GATEWAY_TQ -ge $LOWER_LIMIT ] && [ $GATEWAY_TQ -le $UPPER_LIMIT ]; # This is just to get a clean run if we are in-between the grace periode
> +then
> +	echo "Gateway TQ is $GATEWAY_TQ - Do nothing"
> +fi
> diff --git a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/settings.html b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/settings.html
> index f510431..73e3e59 100755
> --- a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/settings.html
> +++ b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/settings.html
> @@ -64,6 +64,13 @@ if [ "$REQUEST_METHOD" == "POST" ] ; then
>  			fi
>  		fi
>  		
> +		uci -q set "fff.autorestart=settings"
> +		if [ "$POST_autorestart_enabled" == "on" ] ; then
> +			uci -q set "fff.autorestart.enabled=1"
> +		else
> +			uci -q set "fff.autorestart.enabled=0"
> +		fi
> +		
>  		uci commit
>  		MSG='<span class="green">Daten gespeichert! - Bitte Router neustarten.</span>'
>  	fi
> @@ -89,6 +96,11 @@ if [ "$(uci -q get 'fff.notifyupdate.resetonupgrade')" == "0" ] ; then # not set
>  else
>  	upgrade_reset_checked="$chkd"
>  fi
> +if [ "$(uci -q get 'fff.autorestart.enabled')" == "1" ] ; then # not set=0
> +	autorestart_checked="$chkd"
> +else
> +	autorestart_checked=""
> +fi
>  %>
>  <% show_msg %>
>  <form method="post">
> @@ -145,6 +157,9 @@ fi
>  		</td></tr>
>  		<% fi %>
>  		
> +		<tr><th>Auto-restart enabled:</th><td colspan="2">
> +			<input type="checkbox" name="autorestart_enabled" <%= ${autorestart_checked} %>/>
> +		</td></tr>
>  	</table>
>  </fieldset>
>  </td></tr>
> diff --git a/src/packages/fff/fff/Makefile b/src/packages/fff/fff/Makefile
> index 594406d..9eaa0cd 100644
> --- 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-config \
>               +fff-nodewatcher \
>               +fff-web \
>
Adrian Schmutzler Aug. 24, 2017, 1:32 p.m.
Hallo Christian,

danke für ausprobieren.

Zur Praxis: Ich hab die Autostart-Funktion inzwischen seit etwa einem Monat
im Produktiv-Einsatz auf ca. 70 Routern (841, 850RE, 860RE, 1043, Pico).

Funktioniert nicht immer, aber mir hilft es in geschätzt 30-50 % der Fälle,
wo ein Router offline geht.

Interessant wäre auch, ob bei
https://mantis.freifunk-franken.de/view.php?id=26 ein Autorestart dafür
sorgt, dass die Geräte wieder ansprechbar werden.

Zum Inline-Kommentar:
Werde ich mir anschauen. Habe das ehrlich gesagt aus dem Offline-SSID-Skript
einfach abgeschrieben, ohne groß drüber nachzudenken.

Grüße

Adrian

> -----Original Message-----
> From: Christian Dresel [mailto:fff@chrisi01.de]
> Sent: Donnerstag, 24. August 2017 15:07
> To: Adrian Schmutzler <freifunk@adrianschmutzler.de>; franken-
> dev@freifunk.net
> Subject: Re: [PATCH v7 6/6] fff-autorestart: Add autorestart package
> 
> hi
> 
> ich hab mir das Script mal angesehen und auf einen Problemrouter
installiert.
> Scheint soweit zu laufen (zumindest passt die Ausgabe, ob er auch neu
> startet wird sich im problemfall dann zeigen...) muss mir den Code aber
> nochmal in Ruhe angucken. Eine kleine Anmerkung Inline:
> 
> On 21.08.2017 18:43, Adrian Schmutzler wrote:
> > This package implements an auto-restart if the router has not been
> > able to connect to a gateway for more than 30 minutes. If there had
> > been an error or crash causing the interruption, it may be resolved by
> > the restart while no harm is done.
> >
> > After the second restart, the delay is raised so the third and
> > subsequent restarts are limited to one per day.
> >
> > This is a merge of my 3 previous patches introducing the autorestart
> > capability. Now, the autorestart is disabled by default.
> >
> > Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> > ---
> >  src/packages/fff/fff-autorestart/Makefile          | 40
++++++++++++++++
> >  .../files/usr/lib/micron.d/fff-autorestart         |  1 +
> >  .../files/usr/sbin/disable_autorestart.sh          | 15 ++++++
> >  .../files/usr/sbin/enable_autorestart.sh           | 15 ++++++
> >  .../fff-autorestart/files/usr/sbin/offlinerestart  | 53
> ++++++++++++++++++++++
> >  .../fff-web/files/www/ssl/cgi-bin/settings.html    | 15 ++++++
> >  src/packages/fff/fff/Makefile                      |  1 +
> >  7 files changed, 140 insertions(+)
> >  create mode 100644 src/packages/fff/fff-autorestart/Makefile
> >  create mode 100644
> > src/packages/fff/fff-autorestart/files/usr/lib/micron.d/fff-autorestar
> > t  create mode 100755
> > src/packages/fff/fff-autorestart/files/usr/sbin/disable_autorestart.sh
> >  create mode 100755
> > src/packages/fff/fff-autorestart/files/usr/sbin/enable_autorestart.sh
> >  create mode 100755
> > src/packages/fff/fff-autorestart/files/usr/sbin/offlinerestart
> >
> > diff --git a/src/packages/fff/fff-autorestart/Makefile
> > b/src/packages/fff/fff-autorestart/Makefile
> > new file mode 100644
> > index 0000000..8c062e5
> > --- /dev/null
> > +++ b/src/packages/fff/fff-autorestart/Makefile
> > @@ -0,0 +1,40 @@
> > +include $(TOPDIR)/rules.mk
> > +
> > +PKG_NAME:=fff-autorestart
> > +PKG_VERSION:=2
> > +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 +fff-config
> > +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-autorest
> > art
> > b/src/packages/fff/fff-autorestart/files/usr/lib/micron.d/fff-autorest
> > art
> > new file mode 100644
> > index 0000000..885b50a
> > --- /dev/null
> > +++ b/src/packages/fff/fff-autorestart/files/usr/lib/micron.d/fff-auto
> > +++ restart
> > @@ -0,0 +1 @@
> > +*/5 * * * * /usr/sbin/offlinerestart
> > diff --git
> > a/src/packages/fff/fff-autorestart/files/usr/sbin/disable_autorestart.
> > sh
> > b/src/packages/fff/fff-autorestart/files/usr/sbin/disable_autorestart.
> > sh
> > new file mode 100755
> > index 0000000..f83907b
> > --- /dev/null
> > +++ b/src/packages/fff/fff-autorestart/files/usr/sbin/disable_autorest
> > +++ art.sh
> > @@ -0,0 +1,15 @@
> > +#!/bin/sh
> > +# This disables the auto-restart feature permanently # (setting is
> > +preserved during upgrades)
> > +
> > +uci -q set "fff.autorestart=settings"
> > +uci -q set "fff.autorestart.enabled=0"
> > +
> > +uci -q commit fff
> > +
> > +if [ -s /tmp/gatewayoff ] ; then
> > +	rm -f /tmp/gatewayoff
> > +fi
> > +if [ -s /etc/autorestartcount ] ; then
> > +	rm -f /etc/autorestartcount
> > +fi
> > diff --git
> > a/src/packages/fff/fff-autorestart/files/usr/sbin/enable_autorestart.s
> > h
> > b/src/packages/fff/fff-autorestart/files/usr/sbin/enable_autorestart.s
> > h
> > new file mode 100755
> > index 0000000..4f7c3cb
> > --- /dev/null
> > +++ b/src/packages/fff/fff-autorestart/files/usr/sbin/enable_autoresta
> > +++ rt.sh
> > @@ -0,0 +1,15 @@
> > +#!/bin/sh
> > +# This enables the auto-restart feature permanently # (setting is
> > +preserved during upgrades)
> > +
> > +uci -q set "fff.autorestart=settings"
> > +uci -q set "fff.autorestart.enabled=1"
> > +
> > +uci -q commit fff
> > +
> > +if [ -s /tmp/gatewayoff ] ; then
> > +	rm -f /tmp/gatewayoff
> > +fi
> > +if [ -s /etc/autorestartcount ] ; then
> > +	rm -f /etc/autorestartcount
> > +fi
> > 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..5e1ce52
> > --- /dev/null
> > +++ b/src/packages/fff/fff-autorestart/files/usr/sbin/offlinerestart
> > @@ -0,0 +1,53 @@
> > +#!/bin/sh
> > +
> > +if [ ! "$(uci -q get fff.autorestart.enabled)" = "1" ] ; then
> > +	exit 0
> > +fi
> > +
> > +UPPER_LIMIT='50' # Above this limit the gateway will be considered
> > +online LOWER_LIMIT='20' # Below this limit the gateway will be
> > +considered offline # In-between these two values the state is not
> > +changed
> > +
> > +NOW=$(date +%s)
> > +
> > +GATEWAY_TQ=$(batctl gwl | grep "^=>" | awk -F'[()]' '{print $2}'| tr
> > +-d " ") # Grep the connection quality of the gateway which is
> > +currently used
> 
> ich verwende bei mir Batman 2016.5 (dezentrale Hood und so) und da
> kommt kein => mehr drinnen vor (oder liegt es daran, das ich nur ein
> Gateway habe?!). Die Ausgabe sieht bei mir etwas anders aus:
> 
> root@EG1:~# batctl gwl
> [B.A.T.M.A.N. adv 2016.5, MainIF/MAC: eth1.3/f4:f2:6d:9c:8c:c0
> (bat0/86:26:0e:e5:77:3e BATMAN_IV)]
>   Router            ( TQ) Next Hop          [outgoingIf]  Bandwidth
> * 66:66:b3:de:f5:cd (205) 68:72:51:6a:8e:8f [    w2mesh]: 10.0/2.0 MBit
> 
> Ich hab das ganze nun ein klein wenig geändert:
> 
> root@EG1:~# batctl gwl | grep "*" | awk -F'[()]' '{print $2}'| tr -d " "
> 216
> 
> sollte diese Anpassung auch unter 2013.4 mit mehreren GWs gehen, würde
> ich vorschlagen dies so zu übernehmen (außer jemand fällt noch was
> besseres ein)
> 
> mfg
> 
> Christian
> 
> 
> > +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
> > +	if [ -s /etc/autorestartcount ] ; then
> > +		rm -f /etc/autorestartcount
> > +	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)-1800)) # Restart after 30 minutes
> > +	OFFLINEDAY=$(($(date +%s)-86400)) # Restart after 1 day
> > +	if [ "$(cat /tmp/gatewayoff)" -lt "$OFFLINESINCE" ] ; then
> > +		if [ -s /etc/autorestartcount ] ; then # Auto-restart has
> already taken place
> > +		    restartcount="$(cat /etc/autorestartcount)"
> > +			if [ "$restartcount" -lt 2 ] || [ "$(cat
> /tmp/gatewayoff)" -lt "$OFFLINEDAY" ] ; then
> > +				# 1st and 2nd restart after 30 minutes, 3rd+
> restart after one day
> > +				echo $((restartcount + 1)) >
> /etc/autorestartcount
> > +				reboot && exit
> > +			fi
> > +		else
> > +			echo "1" > /etc/autorestartcount
> > +			reboot && exit
> > +		fi
> > +	fi
> > +fi
> > +if [ $GATEWAY_TQ -ge $LOWER_LIMIT ] && [ $GATEWAY_TQ -le
> $UPPER_LIMIT
> > +]; # This is just to get a clean run if we are in-between the grace
periode
> then
> > +	echo "Gateway TQ is $GATEWAY_TQ - Do nothing"
> > +fi
> > diff --git
> > a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/settings.html
> > b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/settings.html
> > index f510431..73e3e59 100755
> > --- a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/settings.html
> > +++ b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/settings.html
> > @@ -64,6 +64,13 @@ if [ "$REQUEST_METHOD" == "POST" ] ; then
> >  			fi
> >  		fi
> >
> > +		uci -q set "fff.autorestart=settings"
> > +		if [ "$POST_autorestart_enabled" == "on" ] ; then
> > +			uci -q set "fff.autorestart.enabled=1"
> > +		else
> > +			uci -q set "fff.autorestart.enabled=0"
> > +		fi
> > +
> >  		uci commit
> >  		MSG='<span class="green">Daten gespeichert! - Bitte Router
> neustarten.</span>'
> >  	fi
> > @@ -89,6 +96,11 @@ if [ "$(uci -q get
> > 'fff.notifyupdate.resetonupgrade')" == "0" ] ; then # not set  else
> >  	upgrade_reset_checked="$chkd"
> >  fi
> > +if [ "$(uci -q get 'fff.autorestart.enabled')" == "1" ] ; then # not
set=0
> > +	autorestart_checked="$chkd"
> > +else
> > +	autorestart_checked=""
> > +fi
> >  %>
> >  <% show_msg %>
> >  <form method="post">
> > @@ -145,6 +157,9 @@ fi
> >  		</td></tr>
> >  		<% fi %>
> >
> > +		<tr><th>Auto-restart enabled:</th><td colspan="2">
> > +			<input type="checkbox"
> name="autorestart_enabled" <%= ${autorestart_checked} %>/>
> > +		</td></tr>
> >  	</table>
> >  </fieldset>
> >  </td></tr>
> > diff --git a/src/packages/fff/fff/Makefile
> > b/src/packages/fff/fff/Makefile index 594406d..9eaa0cd 100644
> > --- 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-config \
> >               +fff-nodewatcher \
> >               +fff-web \
> >