Skip to content

Commit

Permalink
gluon-check-connection: extracted from gluon-scheduled-domain-switch
Browse files Browse the repository at this point in the history
  • Loading branch information
rubo77 committed Apr 23, 2019
1 parent cae79eb commit 99b592e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 12 deletions.
9 changes: 7 additions & 2 deletions docs/package/gluon-scheduled-domain-switch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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',
},
Expand Down
13 changes: 13 additions & 0 deletions package/gluon-check-connection/Makefile
Original file line number Diff line number Diff line change
@@ -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))
3 changes: 3 additions & 0 deletions package/gluon-check-connection/check_site.lua
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package/gluon-scheduled-domain-switch/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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))
1 change: 0 additions & 1 deletion package/gluon-scheduled-domain-switch/check_site.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 99b592e

Please sign in to comment.