refactor: improve graceful shutdown sequencing in start.sh, remove redundant final sync in n8n-sync.py, and update host resolution in health-server.js
Browse files- health-server.js +2 -5
- n8n-sync.py +0 -5
- start.sh +13 -2
health-server.js
CHANGED
|
@@ -436,11 +436,8 @@ function renderDashboard(data) {
|
|
| 436 |
}
|
| 437 |
|
| 438 |
async function resolveSpaceIsPrivate(req) {
|
| 439 |
-
const host = req.headers.host || "";
|
| 440 |
-
|
| 441 |
-
if (!match) return false;
|
| 442 |
-
const user = match[1];
|
| 443 |
-
const space = match[2];
|
| 444 |
|
| 445 |
const params = new URLSearchParams(req.url.split("?")[1] || "");
|
| 446 |
const token = params.get("__sign");
|
|
|
|
| 436 |
}
|
| 437 |
|
| 438 |
async function resolveSpaceIsPrivate(req) {
|
| 439 |
+
const host = (req.headers.host || "").split(":")[0];
|
| 440 |
+
if (!host.endsWith(".hf.space")) return false;
|
|
|
|
|
|
|
|
|
|
| 441 |
|
| 442 |
const params = new URLSearchParams(req.url.split("?")[1] || "");
|
| 443 |
const token = params.get("__sign");
|
n8n-sync.py
CHANGED
|
@@ -208,11 +208,6 @@ def loop() -> int:
|
|
| 208 |
if STOP_EVENT.wait(INTERVAL):
|
| 209 |
break
|
| 210 |
|
| 211 |
-
try:
|
| 212 |
-
sync_once(None)
|
| 213 |
-
except Exception as exc:
|
| 214 |
-
write_status("error", f"Final sync failed: {exc}")
|
| 215 |
-
print(f"Final sync failed: {exc}", file=sys.stderr)
|
| 216 |
return 0
|
| 217 |
|
| 218 |
|
|
|
|
| 208 |
if STOP_EVENT.wait(INTERVAL):
|
| 209 |
break
|
| 210 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
return 0
|
| 212 |
|
| 213 |
|
start.sh
CHANGED
|
@@ -66,9 +66,20 @@ fi
|
|
| 66 |
|
| 67 |
cleanup() {
|
| 68 |
echo "Stopping Hugging8n..."
|
| 69 |
-
[ -n "${SYNC_PID:-}" ] && kill "$SYNC_PID" 2>/dev/null || true
|
| 70 |
-
[ -n "${N8N_PID:-}" ] && kill "$N8N_PID" 2>/dev/null || true
|
| 71 |
[ -n "${PROXY_PID:-}" ] && kill "$PROXY_PID" 2>/dev/null || true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
if [ -n "${HF_TOKEN:-}" ]; then
|
| 73 |
echo "Running final backup pass..."
|
| 74 |
python3 "$APP_DIR/n8n-sync.py" sync-once || true
|
|
|
|
| 66 |
|
| 67 |
cleanup() {
|
| 68 |
echo "Stopping Hugging8n..."
|
|
|
|
|
|
|
| 69 |
[ -n "${PROXY_PID:-}" ] && kill "$PROXY_PID" 2>/dev/null || true
|
| 70 |
+
|
| 71 |
+
# Stop the background sync loop gracefully
|
| 72 |
+
if [ -n "${SYNC_PID:-}" ]; then
|
| 73 |
+
kill "$SYNC_PID" 2>/dev/null || true
|
| 74 |
+
wait "$SYNC_PID" 2>/dev/null || true
|
| 75 |
+
fi
|
| 76 |
+
|
| 77 |
+
# Wait for n8n to finish its graceful shutdown to ensure DB state is flushed
|
| 78 |
+
if [ -n "${N8N_PID:-}" ]; then
|
| 79 |
+
kill -TERM "$N8N_PID" 2>/dev/null || true
|
| 80 |
+
wait "$N8N_PID" 2>/dev/null || true
|
| 81 |
+
fi
|
| 82 |
+
|
| 83 |
if [ -n "${HF_TOKEN:-}" ]; then
|
| 84 |
echo "Running final backup pass..."
|
| 85 |
python3 "$APP_DIR/n8n-sync.py" sync-once || true
|