diff --git a/app/sovran_systemsos_web/static/js/constants.js b/app/sovran_systemsos_web/static/js/constants.js index a13e52a..c1a49c3 100644 --- a/app/sovran_systemsos_web/static/js/constants.js +++ b/app/sovran_systemsos_web/static/js/constants.js @@ -6,6 +6,9 @@ const POLL_INTERVAL_SERVICES = 5000; const POLL_INTERVAL_UPDATES = 1800000; const UPDATE_POLL_INTERVAL = 2000; const REBOOT_CHECK_INTERVAL = 5000; +const REBOOT_FETCH_TIMEOUT = 12000; +const REBOOT_REQUEST_TIMEOUT = 4000; +const REBOOT_INITIAL_DELAY = 25000; const SUPPORT_TIMER_INTERVAL = 1000; const CATEGORY_ORDER = [ diff --git a/app/sovran_systemsos_web/static/js/security.js b/app/sovran_systemsos_web/static/js/security.js index 7f1394f..3a92efd 100644 --- a/app/sovran_systemsos_web/static/js/security.js +++ b/app/sovran_systemsos_web/static/js/security.js @@ -157,14 +157,14 @@ function openSecurityModal() { } }, 1000); - rebootBtn.addEventListener("click", async function() { + rebootBtn.addEventListener("click", function() { rebootBtn.disabled = true; rebootBtn.textContent = "Rebooting\u2026"; - try { - await apiFetch("/api/reboot", { method: "POST" }); - } catch (_) {} if ($rebootOverlay) $rebootOverlay.classList.add("visible"); - setTimeout(waitForServerReboot, REBOOT_CHECK_INTERVAL); + setTimeout(waitForServerReboot, REBOOT_INITIAL_DELAY); + var rebootCtrl = new AbortController(); + setTimeout(function() { rebootCtrl.abort(); }, REBOOT_REQUEST_TIMEOUT); + fetch("/api/reboot", { method: "POST", signal: rebootCtrl.signal }).catch(function() {}); }, { once: true }); } } catch (err) { diff --git a/app/sovran_systemsos_web/static/js/update.js b/app/sovran_systemsos_web/static/js/update.js index ac2e2b9..a109612 100644 --- a/app/sovran_systemsos_web/static/js/update.js +++ b/app/sovran_systemsos_web/static/js/update.js @@ -174,26 +174,28 @@ function doReboot() { if ($rebootOverlay) $rebootOverlay.classList.add("visible"); _rebootStartTime = Date.now(); _serverWentDown = false; - apiFetch("/api/reboot", { method: "POST" }).catch(function() {}); - // Wait 15 seconds before the first check — give the system time to actually shut down - setTimeout(waitForServerReboot, 15000); + var rebootCtrl = new AbortController(); + setTimeout(function() { rebootCtrl.abort(); }, REBOOT_REQUEST_TIMEOUT); + fetch("/api/reboot", { method: "POST", signal: rebootCtrl.signal }).catch(function() {}); + // Wait before the first check — NixOS shutdown after an update can take 20-40s + setTimeout(waitForServerReboot, REBOOT_INITIAL_DELAY); } function waitForServerReboot() { var controller = new AbortController(); - var timeoutId = setTimeout(function() { controller.abort(); }, REBOOT_CHECK_INTERVAL); + var timeoutId = setTimeout(function() { controller.abort(); }, REBOOT_FETCH_TIMEOUT); - fetch("/api/config", { cache: "no-store", signal: controller.signal }) + fetch("/api/config", { cache: "no-store", signal: controller.signal, headers: { "Connection": "close" } }) .then(function(res) { clearTimeout(timeoutId); if (res.ok && _serverWentDown) { // Server is back after having been down — reboot is complete window.location.reload(); - } else if (res.ok && !_serverWentDown && (Date.now() - _rebootStartTime) < 30000) { + } else if (res.ok && !_serverWentDown && (Date.now() - _rebootStartTime) < 90000) { // Server still responding but hasn't gone down yet — keep waiting setTimeout(waitForServerReboot, REBOOT_CHECK_INTERVAL); } else if (res.ok) { - // Been over 30 seconds and server is responding — just reload + // Been over 90 seconds and server is responding — just reload window.location.reload(); } else { _serverWentDown = true;