fix: auto-start on install like ntfy version - dashboard auto-calls /start and auto-restart on 404

- frontend now auto-calls /start (nohup with fallback) 1.5s after detecting stopped, and auto-restarts dashboard 1.5s after detecting 404 (tries /api/gateway/restart, /api/dashboard/restart, etc.)
- keeps passive link display but restores auto behavior like ntfy version: cài vô là tự chạy nohup & tạo link, hiện ra dashboard
- bump v2.3.3
This commit is contained in:
6zev 2026-09-03 05:00:59 +00:00
parent 77514c9470
commit d956b94826
3 changed files with 20 additions and 6 deletions

View File

@ -28,6 +28,7 @@
const [status, setStatus] = React.useState("idle"); const [status, setStatus] = React.useState("idle");
const [msg, setMsg] = React.useState(null); const [msg, setMsg] = React.useState(null);
const [triedAuto, setTriedAuto] = React.useState(false); const [triedAuto, setTriedAuto] = React.useState(false);
const [autoRestarted, setAutoRestarted] = React.useState(false);
const check = React.useCallback(async function(){ const check = React.useCallback(async function(){
try { try {
@ -69,12 +70,25 @@
}, [status, triedAuto, doStart]); }, [status, triedAuto, doStart]);
const restartDashboard = React.useCallback(async function(){ const restartDashboard = React.useCallback(async function(){
setMsg("Đang gửi lệnh restart Gateway/Dashboard..."); if (autoRestarted) return;
try { await fetchJSONAllowError("/api/gateway/restart", {method:"POST"}); } catch(_){} setAutoRestarted(true);
setMsg("Đang gửi lệnh restart Gateway/Dashboard (tự động khi cài)...");
const endpoints = ["/api/gateway/restart","/api/dashboard/restart","/api/hermes/restart","/api/ops/restart","/api/gateway/stop","/api/gateway/start"];
for (const ep of endpoints) {
try { await fetchJSONAllowError(ep, {method:"POST"}); setMsg("Đã gửi "+ep+", đợi 7s..."); break; } catch(_){}
}
try { await fetchJSONAllowError("/api/dashboard/plugins/rescan"); } catch(_){} try { await fetchJSONAllowError("/api/dashboard/plugins/rescan"); } catch(_){}
setMsg("Đã gửi restart, đợi 7s rồi reload..."); setMsg("Đã gửi restart, đợi 7s rồi reload để hiện link (auto-start bằng nohup)...");
setTimeout(function(){ window.location.reload(); }, 7000); setTimeout(function(){ window.location.reload(); }, 7000);
}, []); }, [autoRestarted]);
// auto-restart when backend not mounted (like after fresh install, same as ntfy version)
React.useEffect(function(){
if (status === "needs_restart" && !autoRestarted) {
const t = setTimeout(restartDashboard, 1500);
return function(){ clearTimeout(t); };
}
}, [status, autoRestarted, restartDashboard]);
if (status === "needs_restart") { if (status === "needs_restart") {
return React.createElement(Card, null, return React.createElement(Card, null,

View File

@ -3,7 +3,7 @@
"label": "sshx.io Terminal", "label": "sshx.io Terminal",
"description": "Chỉ hiện link hiện tại — auto-start nohup (fallback), tự gọi /start nếu chưa có link", "description": "Chỉ hiện link hiện tại — auto-start nohup (fallback), tự gọi /start nếu chưa có link",
"icon": "Terminal", "icon": "Terminal",
"version": "2.3.2", "version": "2.3.3",
"tab": { "tab": {
"path": "/sshx", "path": "/sshx",
"position": "end" "position": "end"

View File

@ -1,5 +1,5 @@
name: sshx-link name: sshx-link
version: 2.3.2 version: 2.3.3
description: Tạo shell ở sshx.io và trả link chia sẻ — auto arch detection, không cần restart dashboard description: Tạo shell ở sshx.io và trả link chia sẻ — auto arch detection, không cần restart dashboard
author: sisyphus author: sisyphus
provides_tools: provides_tools: