Merge pull request #2065 from freifunk-gluon/early-reconfigure
Domain switch during reboot/gluon-reload
This commit is contained in:
commit
b1294472c6
@ -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|
|
||||||
|
|
||||||
|
12
package/gluon-core/files/etc/init.d/gluon-core-reconfigure
Executable file
12
package/gluon-core/files/etc/init.d/gluon-core-reconfigure
Executable 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
|
||||||
|
}
|
@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
/etc/init.d/gluon-core-reconfigure start
|
@ -1,3 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
exec uci commit
|
uci -q batch <<-EOF
|
||||||
|
delete gluon.core.reconfigure
|
||||||
|
commit
|
||||||
|
EOF
|
||||||
|
48
package/gluon-core/luasrc/lib/gluon/upgrade/005-set-domain
Executable file
48
package/gluon-core/luasrc/lib/gluon/upgrade/005-set-domain
Executable 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')
|
@ -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')
|
|
56
package/gluon-core/luasrc/usr/bin/gluon-switch-domain
Executable file
56
package/gluon-core/luasrc/usr/bin/gluon-switch-domain
Executable 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})
|
@ -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
|
||||||
|
@ -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
|
|
||||||
|
@ -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")
|
|
@ -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()
|
||||||
|
@ -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))
|
||||||
|
@ -1 +0,0 @@
|
|||||||
/etc/init.d/log
|
|
@ -1 +0,0 @@
|
|||||||
S20network
|
|
@ -1 +0,0 @@
|
|||||||
/etc/init.d/boot
|
|
@ -1 +0,0 @@
|
|||||||
/etc/init.d/umount
|
|
@ -1 +0,0 @@
|
|||||||
/etc/init.d/sysfixtime
|
|
@ -1 +0,0 @@
|
|||||||
/etc/init.d/boot
|
|
@ -1 +0,0 @@
|
|||||||
/etc/init.d/system
|
|
@ -1 +0,0 @@
|
|||||||
/etc/init.d/sysctl
|
|
@ -1 +0,0 @@
|
|||||||
/etc/init.d/log
|
|
@ -1 +0,0 @@
|
|||||||
/etc/init.d/done
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user