mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
sulu: return 503 if usp not ready
This commit is contained in:
parent
426ddd0f30
commit
f1c7fc9e1e
6 changed files with 308 additions and 2 deletions
|
|
@ -98,8 +98,12 @@ define Package/sulu/install/Default
|
|||
$(INSTALL_DIR) $(1)/sulu/
|
||||
$(INSTALL_DIR) $(1)/etc/sulu
|
||||
|
||||
$(INSTALL_DATA) ./files/maintenance.html $(1)/sulu/
|
||||
$(LN) /tmp/sulu $(1)/sulu/connection
|
||||
|
||||
$(INSTALL_BIN) ./files/etc/sulu/sulu.sh $(1)/etc/sulu/
|
||||
$(INSTALL_DATA) ./files/etc/sulu/nginx.locations $(1)/etc/sulu/
|
||||
$(INSTALL_BIN) ./files/etc/sulu/sulu_watcher.sh $(1)/etc/sulu/
|
||||
|
||||
$(INSTALL_DIR) $(1)/etc/users/roles
|
||||
$(INSTALL_DATA) ./files/etc/users/roles/*.json $(1)/etc/users/roles/
|
||||
|
|
@ -109,6 +113,8 @@ define Package/sulu/install/Default
|
|||
ifneq ($(CONFIG_SULU_DEFAULT_UI)$(CONFIG_SULU_BUILDER_DEFAULT_UI),)
|
||||
$(INSTALL_DATA) ./files/etc/uci-defaults/41-make-sulu-default-ui $(1)/etc/uci-defaults/
|
||||
endif
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_BIN) ./files/etc/init.d/sulu $(1)/etc/init.d/
|
||||
endef
|
||||
|
||||
define Package/sulu/install/Post
|
||||
|
|
|
|||
15
sulu/sulu-builder/files/etc/init.d/sulu
Normal file
15
sulu/sulu-builder/files/etc/init.d/sulu
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=9
|
||||
STOP=01
|
||||
|
||||
USE_PROCD=1
|
||||
|
||||
PROG=/etc/sulu/sulu_watcher.sh
|
||||
|
||||
start_service()
|
||||
{
|
||||
procd_open_instance "sulu"
|
||||
procd_set_param command ${PROG}
|
||||
procd_close_instance "sulu"
|
||||
}
|
||||
|
|
@ -8,6 +8,10 @@ location /sitemap.xml {
|
|||
return 200 "User-agent: *\nDisallow: /\n";
|
||||
}
|
||||
|
||||
location /maintenance.html {
|
||||
internal;
|
||||
}
|
||||
|
||||
location /wss {
|
||||
proxy_pass_request_headers on;
|
||||
proxy_cache off;
|
||||
|
|
@ -46,7 +50,10 @@ location / {
|
|||
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,Content-Type,Range' always;
|
||||
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
|
||||
}
|
||||
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
|
||||
add_header Pragma 'no-cache';
|
||||
|
||||
if (!-f $document_root/connection/ready) {
|
||||
return 503;
|
||||
}
|
||||
|
||||
expires 0;
|
||||
}
|
||||
|
|
|
|||
29
sulu/sulu-builder/files/etc/sulu/sulu_watcher.sh
Normal file
29
sulu/sulu-builder/files/etc/sulu/sulu_watcher.sh
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#!/bin/sh
|
||||
|
||||
if ! command -v obuspa >/dev/null 2>&1; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
USP_PATH="/tmp/sulu/"
|
||||
|
||||
log() {
|
||||
logger -t sulu_watcher "$*"
|
||||
}
|
||||
|
||||
wait_for_obuspa() {
|
||||
while true; do
|
||||
ENDPOINTID="$(obuspa -c get Device.LocalAgent.EndpointID |grep Device.|awk '{print $3}')"
|
||||
sleep 2
|
||||
if [ -n "${ENDPOINTID}" ]; then
|
||||
break;
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
mark_usp_ready() {
|
||||
mkdir -p "${USP_PATH}"
|
||||
touch ${USP_PATH}/ready
|
||||
}
|
||||
|
||||
wait_for_obuspa
|
||||
mark_usp_ready
|
||||
|
|
@ -51,6 +51,7 @@ add_sulu_userinterface_uci()
|
|||
uci_set userinterface _sulu_s _nginx_ssl_certificate '/etc/nginx/conf.d/_lan.crt'
|
||||
uci_set userinterface _sulu_s _nginx_ssl_certificate_key '/etc/nginx/conf.d/_lan.key'
|
||||
uci_set userinterface _sulu_s _nginx_ssl_session_cache 'none'
|
||||
uci_set userinterface _sulu_s _nginx_error_page '503 /maintenance.html'
|
||||
uci_set userinterface _sulu_s protocol 'HTTPS'
|
||||
uci_add_list userinterface _sulu_s role 'admin'
|
||||
uci_add_list userinterface _sulu_s role 'user'
|
||||
|
|
|
|||
248
sulu/sulu-builder/files/maintenance.html
Normal file
248
sulu/sulu-builder/files/maintenance.html
Normal file
|
|
@ -0,0 +1,248 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Router Interface Loading...</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family:
|
||||
-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
|
||||
sans-serif;
|
||||
background: linear-gradient(135deg, #3399ff 0%, #012669 100%);
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.container {
|
||||
text-align: center;
|
||||
padding: 2rem;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 20px;
|
||||
backdrop-filter: blur(10px);
|
||||
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
|
||||
max-width: 400px;
|
||||
width: 90%;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
margin: 0 auto 2rem;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.spinner::before,
|
||||
.spinner::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 50%;
|
||||
border: 3px solid transparent;
|
||||
border-top-color: #fff;
|
||||
animation: spin 1.5s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.spinner::after {
|
||||
animation-delay: 0.15s;
|
||||
border-top-color: rgba(255, 255, 255, 0.5);
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 1.8rem;
|
||||
margin-bottom: 1rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 1rem;
|
||||
opacity: 0.9;
|
||||
line-height: 1.5;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.status {
|
||||
font-size: 0.9rem;
|
||||
opacity: 0.8;
|
||||
margin-top: 1.5rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.status-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
background: #fff;
|
||||
border-radius: 50%;
|
||||
animation: pulse 1.5s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%,
|
||||
100% {
|
||||
opacity: 0.3;
|
||||
}
|
||||
50% {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.retry-count {
|
||||
font-size: 0.85rem;
|
||||
opacity: 0.7;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
background: rgba(255, 59, 48, 0.2);
|
||||
border: 1px solid rgba(255, 59, 48, 0.5);
|
||||
padding: 0.75rem;
|
||||
border-radius: 8px;
|
||||
margin-top: 1rem;
|
||||
font-size: 0.9rem;
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="spinner"></div>
|
||||
<h1>Router Starting Up</h1>
|
||||
<p>
|
||||
The web interface is initializing. You'll be redirected automatically
|
||||
once it's ready.
|
||||
</p>
|
||||
|
||||
<div class="status">
|
||||
<span class="status-dot"></span>
|
||||
<span id="statusText">Checking availability...</span>
|
||||
</div>
|
||||
|
||||
<div class="retry-count" id="retryCount"></div>
|
||||
<div class="error-message" id="errorMessage"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let retryCount = 0;
|
||||
let checkInterval = 2000; // Start with 2 seconds
|
||||
let maxInterval = 10000; // Max 10 seconds between checks
|
||||
let consecutiveFailures = 0;
|
||||
let maxConsecutiveFailures = 100; // Stop after 100 consecutive failures (~8-10 minutes)
|
||||
|
||||
function updateStatus(message) {
|
||||
document.getElementById("statusText").textContent = message;
|
||||
}
|
||||
|
||||
function updateRetryCount() {
|
||||
retryCount++;
|
||||
const retryElement = document.getElementById("retryCount");
|
||||
retryElement.textContent = `Attempt ${retryCount}`;
|
||||
}
|
||||
|
||||
function showError(message) {
|
||||
const errorElement = document.getElementById("errorMessage");
|
||||
errorElement.textContent = message;
|
||||
errorElement.style.display = "block";
|
||||
}
|
||||
|
||||
async function checkAvailability() {
|
||||
updateRetryCount();
|
||||
updateStatus("Connecting to router...");
|
||||
|
||||
try {
|
||||
// Try to fetch the index page
|
||||
const response = await fetch("/index.html", {
|
||||
method: "HEAD", // Use HEAD to minimize bandwidth
|
||||
cache: "no-cache",
|
||||
mode: "no-cors", // Allow checking even with CORS restrictions
|
||||
});
|
||||
|
||||
// If we get any response (even 404), the server is responding
|
||||
// For a router, we typically want to redirect on 200 or 304
|
||||
if (response.ok || response.status === 304) {
|
||||
updateStatus("Router ready! Redirecting...");
|
||||
consecutiveFailures = 0;
|
||||
|
||||
// Small delay for user feedback
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 500);
|
||||
return true;
|
||||
} else if (response.status !== 503) {
|
||||
// Server is responding but page not ready yet
|
||||
updateStatus(`Server responding (${response.status}), waiting...`);
|
||||
consecutiveFailures = 0;
|
||||
}
|
||||
} catch (error) {
|
||||
// Network error - server not reachable
|
||||
consecutiveFailures++;
|
||||
|
||||
if (consecutiveFailures > maxConsecutiveFailures) {
|
||||
updateStatus("Connection timeout");
|
||||
showError(
|
||||
"Unable to connect to router. Please check your connection and refresh this page.",
|
||||
);
|
||||
return true; // Stop checking
|
||||
}
|
||||
|
||||
updateStatus("Router not ready yet...");
|
||||
|
||||
// Implement exponential backoff
|
||||
if (consecutiveFailures > 5) {
|
||||
checkInterval = Math.min(checkInterval * 1.2, maxInterval);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
async function startChecking() {
|
||||
// Initial check
|
||||
const isReady = await checkAvailability();
|
||||
if (isReady) return;
|
||||
|
||||
// Continue checking
|
||||
const intervalId = setInterval(async () => {
|
||||
const isReady = await checkAvailability();
|
||||
if (isReady) {
|
||||
clearInterval(intervalId);
|
||||
}
|
||||
}, checkInterval);
|
||||
}
|
||||
|
||||
// Start checking when page loads
|
||||
window.addEventListener("DOMContentLoaded", () => {
|
||||
// Small initial delay to show the UI
|
||||
setTimeout(startChecking, 500);
|
||||
});
|
||||
|
||||
// Also try to check if user clicks anywhere on the page
|
||||
document.addEventListener("click", () => {
|
||||
checkAvailability();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue