diff --git a/multiple-v6-watchdoog/Makefile b/multiple-v6-watchdoog/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..513d65b3c55d6a4ee9b52eb52cdef83a7cbe80ec --- /dev/null +++ b/multiple-v6-watchdoog/Makefile @@ -0,0 +1,51 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=ffnw-multiple-v6-watchdoog +PKG_VERSION:=1 +PKG_RELEASE:=1 + +PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) + +PKG_BUILD_DEPENDS += lua/host luci-base/host + +include $(INCLUDE_DIR)/package.mk + +define Package/ffnw-multiple-v6-watchdoog + SECTION:=networke + CATEGORY:=Freifunk Nordwest + TITLE:=Restart br-client if multiple v6 adresses exsist + DEPENDS:= ffnw-hoodselector +endef + +define Package/ffnw-multiple-v6-watchdoog/description + Restart br-client if multiple v6 adresses exsist +endef + +define SrcDiet + $(FIND) $(1) -type f | while read src; do \ + if $(STAGING_DIR_HOST)/bin/lua $(STAGING_DIR_HOST)/bin/LuaSrcDiet \ + --noopt-binequiv -o "$$$$src.o" "$$$$src"; \ + then mv "$$$$src.o" "$$$$src"; fi; \ + done +endef + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) + $(CP) ./luasrc/* $(PKG_BUILD_DIR)/ + $(call SrcDiet,$(PKG_BUILD_DIR),$(PKG_BUILD_DIR)) + chmod +x -R $(PKG_BUILD_DIR)/ +endef + +define Build/Configure +endef + +define Build/Compile +endef + +define Package/ffnw-multiple-v6-watchdoog/install + $(CP) ./files/* $(1)/ + $(INSTALL_DIR) $(1)/usr/sbin + $(CP) $(PKG_BUILD_DIR)/multiple-v6-watchdoog $(1)/usr/sbin/multiple-v6-watchdoog +endef + +$(eval $(call BuildPackage,ffnw-multiple-v6-watchdoog)) diff --git a/multiple-v6-watchdoog/files/usr/lib/micron.d/multiple-v6-watchdoog b/multiple-v6-watchdoog/files/usr/lib/micron.d/multiple-v6-watchdoog new file mode 100644 index 0000000000000000000000000000000000000000..d77e483d59b71c15ffa99cfb0b7f7aa24e8db603 --- /dev/null +++ b/multiple-v6-watchdoog/files/usr/lib/micron.d/multiple-v6-watchdoog @@ -0,0 +1 @@ +*/2 * * * * /usr/sbin/multiple-v6-watchdoog diff --git a/multiple-v6-watchdoog/luasrc/multiple-v6-watchdoog b/multiple-v6-watchdoog/luasrc/multiple-v6-watchdoog new file mode 100755 index 0000000000000000000000000000000000000000..c86533a73d0388adae0d07f71d010dc8d564ed97 --- /dev/null +++ b/multiple-v6-watchdoog/luasrc/multiple-v6-watchdoog @@ -0,0 +1,56 @@ +#!/usr/bin/lua +local pidPath="/var/run/multiple-v6-watchdoog.pid" + +if io.open(pidPath, "r") ~=nil then + io.stderr:write("The multiple-v6-watchdoog is still running.\n") + os.exit(1) +else + io.close(io.open(pidPath, "w")) +end + +local uci = require('luci.model.uci').cursor() +-- initialization done + +-- Program terminating function including removing of PID file +local function exit() + if io.open(pidPath, "r") ~=nil then + os.remove(pidPath) + end + os.exit(0) +end + +local function brclient_restart() + os.execute('ifconfig br-client down') + os.execute('ifconfig br-client up') + io.stderr:write('Interface br-client restarted.\n') +end + +local found_br_client = false +local br_client = {} +for ifout in io.popen(string.format("ifconfig 2> /dev/null"),'r'):lines() do + if string.find(ifout,"br%-client") then + found_br_client = true + end + if found_br_client then + if ifout == '' then + break + end + if string.find(ifout,"inet6 addr") then + table.insert(br_client, ifout:split(' ')[13]) + end + end +end + +for k, v in pairs( br_client ) do + local count = 0 + for k, vi in pairs( br_client ) do + if v == vi then + count = count +1 + if count >= 2 then + brclient_restart() + exit() + end + end + end +end +exit()