feat: plugin auto-restart dashboard when backend 404

- gateway auto-start now also checks dashboard backend 404 via http://127.0.0.1:9119/api/plugins/sshx-link/status and calls _try_restart_dashboard (systemctl --user restart hermes-dashboard.service, hermes dashboard --stop/start, pkill)
- ensures new plugin_api gets mounted without manual hermes dashboard --stop/start
- keep dashboard visible, no cron needed, auto-start via nohup/systemd
- bump v2.5.8
This commit is contained in:
6zev 2026-09-03 06:04:32 +00:00
parent b0a2fcbc5b
commit e212fe083d
3 changed files with 51 additions and 2 deletions

View File

@ -596,6 +596,22 @@ def _ensure_cron_script():
except Exception as e:
logger.debug(f"ensure cron script failed: {e}")
def _try_restart_dashboard():
for cmd in [
["systemctl","--user","restart","hermes-dashboard.service"],
["systemctl","--user","restart","hermes-dashboard"],
["bash","-c","hermes dashboard --stop; sleep 1; nohup hermes dashboard --host 0.0.0.0 --port 9119 --no-open > /tmp/hermes-dashboard.log 2>&1 &"],
["bash","-c","pkill -f 'hermes.*dashboard'; sleep 1; nohup hermes dashboard --host 0.0.0.0 --port 9119 --no-open > /tmp/hermes-dashboard.log 2>&1 &"],
]:
try:
subprocess.Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL, start_new_session=True)
logger.info(f"dashboard restart tried: {' '.join(cmd)}")
return True
except Exception as e:
logger.debug(f"dashboard restart {cmd} failed: {e}")
continue
return False
def register(ctx):
# ensure cron script is available in HERMES_HOME/scripts for no_agent cron
_ensure_cron_script()
@ -629,6 +645,39 @@ def register(ctx):
threading.Thread(target=_auto_start, daemon=True).start()
# also auto-restart dashboard if backend 404 (plugin updated but dashboard not restarted)
def _auto_restart_dashboard_check():
try:
time.sleep(5)
# check if dashboard backend is 404
import urllib.request, json as _j
for _ in range(3):
try:
req = urllib.request.urlopen("http://127.0.0.1:9119/api/plugins/sshx-link/status", timeout=3)
# if 200, backend mounted, no need
if req.status == 200:
return
except Exception as e:
# try to detect 404 via HTTPError
try:
if hasattr(e, 'code') and e.code == 404:
logger.info("dashboard backend 404 detected, trying restart")
_try_restart_dashboard()
return
except Exception:
pass
# also try via status code in exception
if "404" in str(e):
_try_restart_dashboard()
return
time.sleep(2)
# also check link file exists but dashboard not showing it
if _read_link_file() and not _is_sshx_alive():
_try_restart_dashboard()
except Exception as e:
logger.debug(f"auto restart check failed: {e}")
threading.Thread(target=_auto_restart_dashboard_check, daemon=True).start()
ctx.register_tool(
name="sshx_start",
toolset="sshx-link",

View File

@ -3,7 +3,7 @@
"label": "sshx.io Terminal",
"description": "Auto-start sshx via nohup/systemd, copy cron script to HERMES_HOME/scripts, dashboard visible",
"icon": "Terminal",
"version": "2.5.7",
"version": "2.5.8",
"tab": {
"path": "/sshx",
"position": "end"

View File

@ -1,5 +1,5 @@
name: sshx-link
version: 2.5.7
version: 2.5.8
description: Auto-start sshx via nohup/systemd, copy cron script to HERMES_HOME/scripts, dashboard visible
author: sisyphus
provides_tools: