fix preview runtime isolation and shutdown (#1088)

This commit is contained in:
ekko
2026-05-28 13:50:52 +08:00
committed by GitHub
parent 1734bac9b4
commit d610c3d1b9
17 changed files with 256 additions and 19 deletions
+39
View File
@@ -22,6 +22,9 @@ const TOKEN_FILE = join(PID_DIR, '.token')
const LOGIN_LOCK_FILE = join(WEB_UI_HOME, '.login-lock.json')
const WEB_UI_DB_FILE = join(WEB_UI_HOME, 'hermes-web-ui.db')
const DEFAULT_PORT = 8648
const PREVIEW_BACKEND_PORT = 8650
const PREVIEW_FRONTEND_PORT = 8651
const PREVIEW_AGENT_BRIDGE_PORT = 18650
const DEFAULT_USERNAME = 'admin'
const DEFAULT_PASSWORD = '123456'
@@ -261,6 +264,37 @@ function killListeningPids(port, pids = getListeningPids(port)) {
} catch {}
}
function stopPreviewRuntimeFromCli() {
const previewPorts = [
PREVIEW_BACKEND_PORT,
PREVIEW_FRONTEND_PORT,
...(process.platform === 'win32' ? [PREVIEW_AGENT_BRIDGE_PORT] : []),
]
const pids = [...new Set(previewPorts.flatMap(port => getListeningPids(port)))]
if (!pids.length) return 0
console.log(` ⏹ Stopping preview runtime (PID(s): ${pids.join(' ')})...`)
for (const pid of pids) {
try {
if (process.platform === 'win32') {
execFileSync('taskkill.exe', ['/PID', String(pid), '/T', '/F'], { stdio: 'ignore', windowsHide: true })
} else {
execSync(`kill -TERM -${pid}`, { stdio: 'ignore' })
}
} catch {
try {
if (process.platform === 'win32') {
execFileSync('taskkill.exe', ['/PID', String(pid), '/F'], { stdio: 'ignore', windowsHide: true })
} else {
execSync(`kill -9 ${pid}`, { stdio: 'ignore' })
}
} catch {}
}
}
return pids.length
}
function recoverPidFromPort() {
const port = getPortFromArgs() ?? DEFAULT_PORT
for (const pid of getListeningPids(port)) {
@@ -419,6 +453,7 @@ function startDaemon(port) {
}
function stopDaemon() {
const stoppedPreviewPids = stopPreviewRuntimeFromCli()
const pidFromFile = readPidFile()
if (pidFromFile && !isRunning(pidFromFile)) {
removePid()
@@ -428,6 +463,10 @@ function stopDaemon() {
const pid = pidFromFile ?? recoverPidFromPort()
if (!pid) {
if (stoppedPreviewPids) {
console.log(` ✓ hermes-web-ui preview stopped`)
return
}
console.log(' ✗ hermes-web-ui is not running')
process.exit(1)
}