diff --git a/__init__.py b/__init__.py index 92dbb10..3a243b6 100644 --- a/__init__.py +++ b/__init__.py @@ -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", diff --git a/dashboard/manifest.json b/dashboard/manifest.json index b53671f..db19703 100644 --- a/dashboard/manifest.json +++ b/dashboard/manifest.json @@ -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" diff --git a/plugin.yaml b/plugin.yaml index c884c9b..b79bb7f 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -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: