fix: clean stale pid on stop (#1015)
This commit is contained in:
+13
-1
@@ -419,7 +419,14 @@ function startDaemon(port) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function stopDaemon() {
|
function stopDaemon() {
|
||||||
const pid = getPid()
|
const pidFromFile = readPidFile()
|
||||||
|
if (pidFromFile && !isRunning(pidFromFile)) {
|
||||||
|
removePid()
|
||||||
|
console.log(` ✓ hermes-web-ui was not running (cleaned stale PID: ${pidFromFile})`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const pid = pidFromFile ?? recoverPidFromPort()
|
||||||
if (!pid) {
|
if (!pid) {
|
||||||
console.log(' ✗ hermes-web-ui is not running')
|
console.log(' ✗ hermes-web-ui is not running')
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
@@ -442,7 +449,11 @@ function stopDaemon() {
|
|||||||
} catch {}
|
} catch {}
|
||||||
// Force kill if still alive
|
// Force kill if still alive
|
||||||
if (isRunning(pid)) {
|
if (isRunning(pid)) {
|
||||||
|
try {
|
||||||
process.kill(pid, 'SIGKILL')
|
process.kill(pid, 'SIGKILL')
|
||||||
|
} catch (err) {
|
||||||
|
if (err?.code !== 'ESRCH') throw err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
removePid()
|
removePid()
|
||||||
console.log(` ✓ hermes-web-ui stopped (PID: ${pid})`)
|
console.log(` ✓ hermes-web-ui stopped (PID: ${pid})`)
|
||||||
@@ -701,4 +712,5 @@ export {
|
|||||||
getListeningPids,
|
getListeningPids,
|
||||||
parseUnixNetstatListeningPids,
|
parseUnixNetstatListeningPids,
|
||||||
resetDefaultLogin,
|
resetDefaultLogin,
|
||||||
|
stopDaemon,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,6 +125,22 @@ describe('CLI port detection', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('cleans a stale server PID file during stop', async () => {
|
||||||
|
const home = mkdtempSync(join(tmpdir(), 'hermes-web-ui-cli-stale-pid-'))
|
||||||
|
process.env.HERMES_WEB_UI_HOME = home
|
||||||
|
const pidFile = join(home, 'server.pid')
|
||||||
|
writeFileSync(pidFile, '999999999\n')
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { stopDaemon } = await loadCli()
|
||||||
|
stopDaemon()
|
||||||
|
|
||||||
|
expect(existsSync(pidFile)).toBe(false)
|
||||||
|
} finally {
|
||||||
|
rmSync(home, { recursive: true, force: true })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
it('resets an existing admin user to the default password', async () => {
|
it('resets an existing admin user to the default password', async () => {
|
||||||
const home = mkdtempSync(join(tmpdir(), 'hermes-web-ui-cli-default-login-'))
|
const home = mkdtempSync(join(tmpdir(), 'hermes-web-ui-cli-default-login-'))
|
||||||
process.env.HERMES_WEB_UI_HOME = home
|
process.env.HERMES_WEB_UI_HOME = home
|
||||||
|
|||||||
Reference in New Issue
Block a user