gluon-check-connection: extracted from gluon-scheduled-domain-switch
This commit is contained in:
parent
255c0045e7
commit
7ae6552d80
@ -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',
|
||||
},
|
||||
|
13
package/gluon-check-connection/Makefile
Normal file
13
package/gluon-check-connection/Makefile
Normal 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))
|
1
package/gluon-check-connection/check_site.lua
Normal file
1
package/gluon-check-connection/check_site.lua
Normal file
@ -0,0 +1 @@
|
||||
need_string_array_match({'check_connection', 'targets'}, '^[%x:]+$')
|
@ -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
|
@ -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))
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user