gluon-check-connection: extracted from gluon-scheduled-domain-switch

This commit is contained in:
rubo77 2019-03-24 09:32:14 +01:00 committed by Ruben Barkow
parent 255c0045e7
commit 7ae6552d80
No known key found for this signature in database
GPG Key ID: 8BCC811299DBC5DF
7 changed files with 28 additions and 15 deletions

View File

@ -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',
},

View File

@ -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))

View File

@ -0,0 +1 @@
need_string_array_match({'check_connection', 'targets'}, '^[%x:]+$')

View File

@ -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

View File

@ -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))

View File

@ -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

View File

@ -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