(sessionsDir: string)
| 96 | } |
| 97 | |
| 98 | export function cleanupStaleAppLogProcesses(sessionsDir: string): void { |
| 99 | if (!fs.existsSync(sessionsDir)) return; |
| 100 | const entries = fs.readdirSync(sessionsDir, { withFileTypes: true }); |
| 101 | for (const entry of entries) { |
| 102 | if (!entry.isDirectory()) continue; |
| 103 | const pidPath = path.join(sessionsDir, entry.name, APP_LOG_PID_FILENAME); |
| 104 | if (!fs.existsSync(pidPath)) continue; |
| 105 | try { |
| 106 | const meta = parsePidFile(fs.readFileSync(pidPath, 'utf8')); |
| 107 | if (meta && shouldTerminateStoredProcess(meta)) { |
| 108 | try { |
| 109 | process.kill(meta.pid, 'SIGTERM'); |
| 110 | } catch { |
| 111 | // process already gone |
| 112 | } |
| 113 | } |
| 114 | } catch { |
| 115 | // ignore malformed pid files |
| 116 | } finally { |
| 117 | clearPidFile(pidPath); |
| 118 | } |
| 119 | } |
| 120 | } |
no test coverage detected