diff --git a/docs/package/gluon-scheduled-domain-switch.rst b/docs/package/gluon-scheduled-domain-switch.rst index 2cef8e4cc4f..17d124ca986 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 00000000000..9e99c59a0d8 --- /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 @GLUON_MULTIDOMAIN +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 00000000000..5b0206549c8 --- /dev/null +++ b/package/gluon-check-connection/check_site.lua @@ -0,0 +1,3 @@ +if need_table(in_domain({'check_connection'}), nil, false) then + need_string_array_match(in_domain({'check_connection', 'targets'}), '^[%x:]+$') +end 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 75% 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 508cd17a6e7..055cb5df687 100755 --- a/package/gluon-scheduled-domain-switch/luasrc/usr/bin/gluon-check-connection +++ b/package/gluon-check-connection/luasrc/usr/bin/gluon-check-connection @@ -7,14 +7,8 @@ local site = require 'gluon.site' local offline_flag_file = "/tmp/gluon_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 b1d7f786daa..fede8f0c12b 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 d1a2fa21260..34ee9895e3a 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'}), check_domain_switch, 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 57fed15a2a4..616f87c0bde 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,7 +5,7 @@ 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) function switch_after_min_reached() if not unistd.access("/tmp/gluon_offline") then return false