Merge pull request #2065 from freifunk-gluon/early-reconfigure

Domain switch during reboot/gluon-reload
This commit is contained in:
Martin Weinelt 2020-08-22 19:50:55 +02:00 committed by GitHub
commit b1294472c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 167 additions and 58 deletions

View File

@ -88,18 +88,25 @@ domain of a router, if and only if one of the above conditions matches.
Switching the domain Switching the domain
-------------------- --------------------
**via commandline**: Via commandline
^^^^^^^^^^^^^^^
:: ::
uci set gluon.core.domain="newdomaincode" gluon-switch-domain 'newdomaincode'
gluon-reconfigure
reboot
**via config mode:** When the node is not in config mode, ``gluon-switch-domain`` will automatically
reboot the node by default. This can be suppressed by passing ``--no-reboot``::
To allow switching the domain via config mode, ``config-mode-domain-select`` gluon-switch-domain --no-reboot 'newdomaincode'
has to be added to GLUON_FEATURES in the site.mk.
Switching the domain without reboot is currently **experimental**.
Via config mode
^^^^^^^^^^^^^^^
To allow switching the domain via config mode, add ``config-mode-domain-select``
to GLUON_FEATURES in site.mk.
|image0| |image0|

View File

@ -0,0 +1,12 @@
#!/bin/sh /etc/rc.common
# Start right after S10boot
START=10
start() {
config_load gluon
config_get_bool reconfigure core reconfigure 0
if [ "$reconfigure" = 1 ]; then
gluon-reconfigure
fi
}

View File

@ -0,0 +1,2 @@
#!/bin/sh
/etc/init.d/gluon-core-reconfigure start

View File

@ -1,3 +1,6 @@
#!/bin/sh #!/bin/sh
exec uci commit uci -q batch <<-EOF
delete gluon.core.reconfigure
commit
EOF

View File

@ -0,0 +1,48 @@
#!/usr/bin/lua
local unistd = require 'posix.unistd'
if not unistd.access('/lib/gluon/domains/') then
return
end
local function domain_exists(domain)
return unistd.access('/lib/gluon/domains/' .. domain .. '.json') == 0
end
local uci = require('simple-uci').cursor()
local domain = uci:get('gluon', 'core', 'switch_domain')
if domain and not domain_exists(domain) then
io.stderr:write(
string.format("Warning: invalid mesh domain switch to '%s' configured, not switching\n", domain)
)
domain = nil
end
if not domain then
domain = uci:get('gluon', 'core', 'domain')
end
if domain and not domain_exists(domain) then
io.stderr:write(
string.format("Warning: invalid mesh domain '%s' configured, resetting to default...\n", domain)
)
domain = nil
end
if not domain then
-- We can't use gluon.site yet, as it depends on gluon.core.domain to be set
local json = require 'jsonc'
local site = assert(json.load('/lib/gluon/site.json'))
domain = site.default_domain
end
uci:set('gluon', 'core', 'domain', domain)
uci:delete('gluon', 'core', 'switch_domain')
uci:save('gluon')

View File

@ -1,27 +0,0 @@
#!/usr/bin/lua
local unistd = require 'posix.unistd'
if not unistd.access('/lib/gluon/domains/') then
return
end
local uci = require('simple-uci').cursor()
local domain = uci:get('gluon', 'core', 'domain')
if domain and not unistd.access('/lib/gluon/domains/' .. domain .. '.json') then
io.stderr:write(string.format("Warning: invalid mesh domain '%s' configured, resetting to default...\n", domain))
domain = nil
end
if domain then return end
-- We can't use gluon.site yet, as it depends on gluon.core.domain to be set
local json = require 'jsonc'
local site = assert(json.load('/lib/gluon/site.json'))
uci:set('gluon', 'core', 'domain', site.default_domain)
uci:commit('gluon')

View File

@ -0,0 +1,56 @@
#!/usr/bin/lua
local unistd = require 'posix.unistd'
local function shift()
table.remove(arg, 1)
end
local reboot = true
if arg[1] == '--no-reboot' then
reboot = false
shift()
end
local setup_mode = unistd.access('/var/gluon/setup-mode') == 0
if #arg ~= 1 then
io.stderr:write('Usage: gluon-switch-domain [--no-reboot] <domain>\n')
os.exit(1)
end
local domain = arg[1]
if not unistd.access('/lib/gluon/domains/') then
io.stderr:write('This Gluon firmware does not support multiple mesh domains.\n')
os.exit(1)
end
local function domain_exists(dom)
return unistd.access('/lib/gluon/domains/' .. dom .. '.json') == 0
end
if not domain_exists(domain) then
io.stderr:write(string.format("Error: invalid mesh domain '%s'\n", domain))
os.exit(1)
end
local uci = require('simple-uci').cursor()
uci:set('gluon', 'core', 'switch_domain', domain)
uci:set('gluon', 'core', 'reconfigure', true)
uci:save('gluon')
local cmd
if setup_mode then
cmd = 'gluon-reconfigure'
elseif reboot then
uci:commit('gluon')
cmd = 'reboot'
else
cmd = 'gluon-reload'
end
unistd.execp(cmd, {[0] = cmd})

View File

@ -67,9 +67,7 @@ end
function M.set_domain_config(domain) function M.set_domain_config(domain)
if uci:get('gluon', 'core', 'domain') ~= domain.domain_code then if uci:get('gluon', 'core', 'domain') ~= domain.domain_code then
uci:set('gluon', 'core', 'domain', domain.domain_code) os.execute(string.format("exec gluon-switch-domain --no-reboot '%s'", domain.domain_code))
uci:commit('gluon')
os.execute('gluon-reconfigure')
M.log('Set domain "'..domain.domain.domain_names[domain.domain_code]..'"') M.log('Set domain "'..domain.domain.domain_names[domain.domain_code]..'"')
return true return true
end end

View File

@ -40,7 +40,6 @@ if geo.lat ~= nil and geo.lon ~= nil then
local geo_base_domain = hoodutil.get_domain_by_geo(jdomains, geo) local geo_base_domain = hoodutil.get_domain_by_geo(jdomains, geo)
if geo_base_domain ~= nil then if geo_base_domain ~= nil then
if hoodutil.set_domain_config(geo_base_domain) then if hoodutil.set_domain_config(geo_base_domain) then
os.execute("gluon-reload")
hoodutil.log('Domain set by geolocation mode.\n') hoodutil.log('Domain set by geolocation mode.\n')
end end
return return
@ -51,6 +50,4 @@ else
end end
-- default domain mode -- default domain mode
if hoodutil.set_domain_config(hoodutil.get_default_domain(hoodutil.get_domains())) then hoodutil.set_domain_config(hoodutil.get_default_domain(hoodutil.get_domains()))
os.execute("gluon-reload")
end

View File

@ -60,8 +60,5 @@ if not switch_after_min_reached() and not switch_time_passed() then
os.exit(0) os.exit(0)
end end
uci:set("gluon", "core", "domain", target_domain) local cmd = {[0] = 'gluon-switch-domain', target_domain}
uci:commit("gluon") unistd.execp(cmd[0], cmd)
os.execute("gluon-reconfigure")
os.execute("reboot")

View File

@ -14,5 +14,5 @@ end
-- Only in case domain switch is scheduled -- Only in case domain switch is scheduled
local f = io.open(cronfile, "w") local f = io.open(cronfile, "w")
f:write("* * * * * /usr/bin/gluon-check-connection\n") f:write("* * * * * /usr/bin/gluon-check-connection\n")
f:write("*/5 * * * * /usr/bin/gluon-switch-domain\n") f:write("*/5 * * * * /lib/gluon/scheduled-domain-switch/switch-domain\n")
f:close() f:close()

View File

@ -17,4 +17,26 @@ define Package/gluon-setup-mode/description
Offline mode to perform basic setup in a secure manner. Offline mode to perform basic setup in a secure manner.
endef endef
init_links := \
K89log \
K98boot \
K99umount \
S00sysfixtime \
S10boot \
S10gluon-core-reconfigure \
S10system \
S11sysctl \
S12log \
S95done
define Package/gluon-setup-mode/install
$(Gluon/Build/Install)
$(LN) S20network $(1)/lib/gluon/setup-mode/rc.d/K90network
for link in $(init_links); do \
$(LN) "/etc/init.d/$$$${link:3}" "$(1)/lib/gluon/setup-mode/rc.d/$$$${link}"; \
done
endef
$(eval $(call BuildPackageGluon,gluon-setup-mode)) $(eval $(call BuildPackageGluon,gluon-setup-mode))

View File

@ -1 +0,0 @@
/etc/init.d/log

View File

@ -1 +0,0 @@
/etc/init.d/boot

View File

@ -1 +0,0 @@
/etc/init.d/umount

View File

@ -1 +0,0 @@
/etc/init.d/sysfixtime

View File

@ -1 +0,0 @@
/etc/init.d/boot

View File

@ -1 +0,0 @@
/etc/init.d/system

View File

@ -1 +0,0 @@
/etc/init.d/sysctl

View File

@ -1 +0,0 @@
/etc/init.d/log

View File

@ -1 +0,0 @@
/etc/init.d/done

View File

@ -7,6 +7,10 @@ setup_mode_enable() {
if [ "$enabled" = 1 ] || [ "$configured" != 1 ]; then if [ "$enabled" = 1 ] || [ "$configured" != 1 ]; then
echo '/lib/gluon/setup-mode/rc.d' > /tmp/rc_d_path echo '/lib/gluon/setup-mode/rc.d' > /tmp/rc_d_path
# This directory is a marker for scripts to know that we're
# in config mode, but it is also used for temporary files
mkdir -p /var/gluon/setup-mode
fi fi
} }