Improve the reboot/flash timers (#1155)

During the initial setup the IP address of the node can move
around a fair bit. Make sure the reboot timeout code handles this.
This commit is contained in:
Tim Wilkinson 2024-04-04 12:10:58 -07:00 committed by GitHub
parent e51fedc394
commit 0dba2661c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 33 additions and 16 deletions

View File

@ -158,18 +158,23 @@ function html.navbar_admin(selected)
html.print("</tr><tr><td colspan=100%><hr></td></tr></table>")
end
function html.wait_for_reboot(delay, countdown)
function html.wait_for_reboot(delay, countdown, address)
if address then
address = [["http://]] .. address .. [[/cgi-bin/status"]]
else
address = [[window.origin + "/cgi-bin/status"]]
end
html.print([[
<script>
const TIMEOUT = 5000;
function reload() {
const start = Date.now();
const req = new XMLHttpRequest();
req.open('GET', window.origin + "/cgi-bin/status");
req.open('GET', ]] .. address .. [[);
req.onreadystatechange = function() {
if (req.readyState === 4) {
if (req.status === 200) {
window.location = window.origin + "/cgi-bin/status";
window.location = ]] .. address .. [[;
}
else {
const time = Date.now() - start;
@ -238,14 +243,21 @@ function html.reboot()
end
http_header()
if fromlan and subnet_change then
html.header(node .. " rebooting", true);
html.print("<body><center>")
html.header(node .. " rebooting", false);
local cursor = uci.cursor()
local wifiip = cursor:get("network", "wifi", "ipaddr")
if not wifiip then
wifiip = "localnode.local.mesh"
end
html.wait_for_reboot(20, 120, wifiip)
html.print("</head><body><center>")
html.print("<h1>" .. node .. " is rebooting</h1><br>")
html.print("<h3>The LAN subnet has changed. You will need to acquire a new DHCP lease<br>")
html.print("and reset any name service caches you may be using.</h3><br>")
html.print("<h3>When the node reboots you get your new DHCP lease and reconnect with<br>")
html.print("<a href='http://localnode.local.mesh:8080/'>http://localnode.local.mesh:8080/</a><br>or<br>")
html.print("<a href='http://" .. node .. ".local.mesh:8080/'>http://" .. node .. ".local.mesh:8080/</a></h3>")
html.print("<br><h1 id='countdown'></h1>")
else
html.header(node .. " rebooting", false)
html.wait_for_reboot(20, 120)

View File

@ -49,6 +49,7 @@ http_output = nil
function http_header(disable_compression)
print "Content-type: text/html\r"
print "Cache-Control: no-store\r"
print("Access-Control-Allow-Origin: *\r")
if not disable_compression then
local encoding = os.getenv("HTTP_ACCEPT_ENCODING")
if encoding and encoding:match("gzip") then

View File

@ -447,10 +447,23 @@ if fw_install and nixio.fs.stat(tmpdir .. "/firmware") then
end
nixio.fs.symlink("/www/aredn.css", "/tmp/web/style.css")
end
-- Show a different reload address if we're running on the ramdisk
local displayaddress = "192.168.1.1"
local waitaddress = displayaddress
if parms.checkbox_keep_settings then
for line in io.lines("/proc/mounts")
do
if line:match("overlay") or line:match("ext4") then
displayaddress = node .. ".local.mesh"
waitaddress = nil
break
end
end
end
html.print("<style>")
html.print(read_all("/tmp/web/style.css"))
html.print("</style>")
html.wait_for_reboot(120, 300)
html.wait_for_reboot(120, 300, waitaddress)
html.print("</head>")
html.print("<body><center>")
html.print("<h2>The firmware is being updated.</h2>")
@ -483,15 +496,6 @@ if fw_install and nixio.fs.stat(tmpdir .. "/firmware") then
aredn.info.set_nvram("nodeupgraded", "0")
os.execute("reboot >/dev/null 2>&1")
else
-- Show a different reload address if we're running on the ramdisk
local hostname = "192.168.1.1"
for line in io.lines("/proc/mounts")
do
if line:match("overlay") or line:match("ext4") then
hostname = node .. ".local.mesh"
break
end
end
html.print([[
<center><h2>Firmware will be written in the background.</h2>
<h3>If your computer is connected to the LAN of this node you may need to acquire<br>
@ -499,7 +503,7 @@ if fw_install and nixio.fs.stat(tmpdir .. "/firmware") then
<h3>The node will reboot twice while the configuration is applied<br>
When the node has finished booting you should ensure your computer has<br>
received a new IP address and reconnect with<br>
<a href='http://]] .. hostname .. [[:8080/'>http://]] .. hostname .. [[:8080/</a><br>
<a href='http://]] .. displayaddress .. [[:8080/'>http://]] .. displayaddress .. [[:8080/</a><br>
This page will automatically reload once the upgrade has completed</h3>
<br><h1 id='countdown'></h1>
</center></body></html>