[RFC PATCH v4 09/11] fff-autorestart: Add autorestart package

Christian Dresel fff at chrisi01.de
So Aug 20 12:20:19 CEST 2017


hi

seh ich das richtig das diese Funktion immer an ist? Wenn ja bin ich
dagegen es einzubauen, vllt. will man ja auch Router ohne Gateways
betreiben? Gerade beim testen von Firmware können solche Reboots sehr
nervig werden, ich erinnere hier mal an diesen Fall:
https://mantis.freifunk-franken.de/view.php?id=23
das war ziemlich nervig (weil ich nicht gleich drauf kam woran es liegt)
und ich möchte nicht, das mir ein Router "unter dem Arsch von selbst neu
bootet" wenn ich grad dran rumbastel.

Als zusätzliche Option im WebUI mit einen Haken wo eine kurze Erklärung
für den User dabei steht, könnte mich evtl. überzeugen es mit
einzubauen, dann kann ein User der dies gerne nutzen möchte
selbstständig aktivieren.

mfg

Christian

On 21.07.2017 15:08, 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. Setting
> /tmp/gatewayoff to '0' disables the whole process.
> 
> After the second restart, the delay is raised so the third and
> subsequent restarts are limited to one per day.
> 
> This is an alternative to my earlier RFC, limiting the number
> of restarts per time, but therefore introducing a small file
> on the non-volatile memory.
> 
> Signed-off-by: Adrian Schmutzler <freifunk at adrianschmutzler.de>
> 
> Tested-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  | 53 ++++++++++++++++++++++
>  src/packages/fff/fff/Makefile                      |  1 +
>  4 files changed, 95 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/offlinerestart
> 
> diff --git a/src/packages/fff/fff-autorestart/Makefile b/src/packages/fff/fff-autorestart/Makefile
> new file mode 100644
> index 0000000..b48542a
> --- /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
> +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..808ea11
> --- /dev/null
> +++ b/src/packages/fff/fff-autorestart/files/usr/sbin/offlinerestart
> @@ -0,0 +1,53 @@
> +#!/bin/sh
> +
> +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)
> +
> +if [ -s /tmp/gatewayoff ] && grep -q '0' /tmp/gatewayoff ; then
> +    exit 0
> +fi
> +
> +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/Makefile b/src/packages/fff/fff/Makefile
> index b039c2d..f498435 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-nodewatcher \
>               +fff-web \
>               +fff-uradvd \
> 

-------------- nächster Teil --------------
Ein Dateianhang mit Binärdaten wurde abgetrennt...
Dateiname   : signature.asc
Dateityp    : application/pgp-signature
Dateigröße  : 819 bytes
Beschreibung: OpenPGP digital signature
URL         : <http://lists.freifunk.net/pipermail/franken-dev-freifunk.net/attachments/20170820/c5e1a432/attachment.sig>


Mehr Informationen über die Mailingliste franken-dev