From 7ae6552d80d1b7dd99e54a40012b3a7ea1ec82c0 Mon Sep 17 00:00:00 2001 From: rubo77 Date: Sun, 24 Mar 2019 09:32:14 +0100 Subject: [PATCH] gluon-check-connection: extracted from gluon-scheduled-domain-switch --- docs/package/gluon-scheduled-domain-switch.rst | 9 +++++++-- package/gluon-check-connection/Makefile | 13 +++++++++++++ package/gluon-check-connection/check_site.lua | 1 + .../luasrc/usr/bin/gluon-check-connection | 10 ++-------- package/gluon-scheduled-domain-switch/Makefile | 2 +- .../gluon-scheduled-domain-switch/check_site.lua | 1 - .../luasrc/usr/bin/gluon-switch-domain | 7 ++++--- 7 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 package/gluon-check-connection/Makefile create mode 100644 package/gluon-check-connection/check_site.lua rename package/{gluon-scheduled-domain-switch => gluon-check-connection}/luasrc/usr/bin/gluon-check-connection (69%) diff --git a/docs/package/gluon-scheduled-domain-switch.rst b/docs/package/gluon-scheduled-domain-switch.rst index ee1fe146..0528e850 100644 --- a/docs/package/gluon-scheduled-domain-switch.rst +++ b/docs/package/gluon-scheduled-domain-switch.rst @@ -21,7 +21,9 @@ domain_switch : optional (needed for domains to switch) - amount of time without reachable gateway to switch unconditionally switch_time : - UNIX epoch after which domain will be switched - connection_check_targets : + +check_connection : + targets : - array of IPv6 addresses which are probed to determine if the node is connected to the mesh @@ -31,7 +33,10 @@ Example:: target_domain = 'new_domain', switch_after_offline_mins = 120, switch_time = 1546344000, -- 01.01.2019 - 12:00 UTC - connection_check_targets = { + }, + + check_connection = { + targets = { '2001:4860:4860::8888', '2001:4860:4860::8844', }, diff --git a/package/gluon-check-connection/Makefile b/package/gluon-check-connection/Makefile new file mode 100644 index 00000000..21d3a7e6 --- /dev/null +++ b/package/gluon-check-connection/Makefile @@ -0,0 +1,13 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=gluon-check-connection +PKG_VERSION:=1 + +include ../gluon.mk + +define Package/gluon-check-connection + TITLE:=Checks if a node can ping definable targets + DEPENDS:=+gluon-core +endef + +$(eval $(call BuildPackageGluon,gluon-check-connection)) diff --git a/package/gluon-check-connection/check_site.lua b/package/gluon-check-connection/check_site.lua new file mode 100644 index 00000000..819beebb --- /dev/null +++ b/package/gluon-check-connection/check_site.lua @@ -0,0 +1 @@ +need_string_array_match({'check_connection', 'targets'}, '^[%x:]+$') diff --git a/package/gluon-scheduled-domain-switch/luasrc/usr/bin/gluon-check-connection b/package/gluon-check-connection/luasrc/usr/bin/gluon-check-connection similarity index 69% rename from package/gluon-scheduled-domain-switch/luasrc/usr/bin/gluon-check-connection rename to package/gluon-check-connection/luasrc/usr/bin/gluon-check-connection index 508cd17a..5556226c 100755 --- a/package/gluon-scheduled-domain-switch/luasrc/usr/bin/gluon-check-connection +++ b/package/gluon-check-connection/luasrc/usr/bin/gluon-check-connection @@ -4,17 +4,11 @@ local unistd = require 'posix.unistd' local util = require 'gluon.util' local site = require 'gluon.site' -local offline_flag_file = "/tmp/gluon_offline" +local offline_flag_file = "/var/gluon/check-connection/offline" local is_offline = true --- Check if domain-switch is scheduled -if site.domain_switch() == nil then - -- Switch not applicable for current domain - os.exit(0) -end - -- Check reachability of pre-defined targets -for _, ip in ipairs(site.domain_switch.connection_check_targets()) do +for _, ip in ipairs(site.check_connection.targets()) do local exit_code = os.execute("ping -c 1 -w 10 " .. ip) if exit_code == 0 then is_offline = false diff --git a/package/gluon-scheduled-domain-switch/Makefile b/package/gluon-scheduled-domain-switch/Makefile index b1d7f786..fede8f0c 100644 --- a/package/gluon-scheduled-domain-switch/Makefile +++ b/package/gluon-scheduled-domain-switch/Makefile @@ -7,7 +7,7 @@ include ../gluon.mk define Package/gluon-scheduled-domain-switch TITLE:=Allows scheduled migrations between domains - DEPENDS:=+gluon-core @GLUON_MULTIDOMAIN + DEPENDS:=+gluon-core +gluon-check-connection @GLUON_MULTIDOMAIN endef $(eval $(call BuildPackageGluon,gluon-scheduled-domain-switch)) diff --git a/package/gluon-scheduled-domain-switch/check_site.lua b/package/gluon-scheduled-domain-switch/check_site.lua index 00feec76..90ed7819 100644 --- a/package/gluon-scheduled-domain-switch/check_site.lua +++ b/package/gluon-scheduled-domain-switch/check_site.lua @@ -2,5 +2,4 @@ if need_table(in_domain({'domain_switch'}), nil, false) then need_domain_name(in_domain({'domain_switch', 'target_domain'})) need_number(in_domain({'domain_switch', 'switch_after_offline_mins'})) need_number(in_domain({'domain_switch', 'switch_time'})) - need_string_array_match(in_domain({'domain_switch', 'connection_check_targets'}), '^[%x:]+$') end diff --git a/package/gluon-scheduled-domain-switch/luasrc/usr/bin/gluon-switch-domain b/package/gluon-scheduled-domain-switch/luasrc/usr/bin/gluon-switch-domain index 31fcea36..88e311f7 100755 --- a/package/gluon-scheduled-domain-switch/luasrc/usr/bin/gluon-switch-domain +++ b/package/gluon-scheduled-domain-switch/luasrc/usr/bin/gluon-switch-domain @@ -5,9 +5,10 @@ local unistd = require 'posix.unistd' local util = require 'gluon.util' local site = require 'gluon.site' --- Returns true if node was offline long enough to perform domain switch +-- Returns true if node was offline long enough to perform domain switch (set by gluon-check-connection) local function switch_after_min_reached() - if not unistd.access("/tmp/gluon_offline") then + local offline_flag_file = "/var/gluon/check-connection/offline" + if not unistd.access(offline_flag_file) then return false end @@ -18,7 +19,7 @@ local function switch_after_min_reached() return false end - local f = util.readfile("/tmp/gluon_offline") + local f = util.readfile(offline_flag_file) if f == nil then return false end