feat(cli): add threatcrush restart - #167
Merged
Merged
Conversation
`start` and `stop` already existed; the documented way to reload the daemon was `threatcrush stop && threatcrush start`. Add `restart` as a first-class command and point the module-reload hint, the SDK README and the docs page at it. Two correctness fixes fall out of doing it properly: - `daemonStop` read `process.kill(pid, 0)` throwing as "the process is gone", but EPERM means the opposite - it's alive and we may not signal it. A non-root client stopping a root-owned daemon would report success while the daemon kept running. It now uses `isProcessAlive` (which already handles EPERM), keeps the pidfile when the daemon survives, and returns whether the daemon is actually down so `restart` can refuse to start a second one over a live socket. - A SIGKILLed daemon leaves its socket file behind, and `daemonStart` treats socket existence as "it came up". Without clearing it first, restart would print a green checkmark for a daemon that never bound. `releaseStaleSocket` waits for the file to go and unlinks it if not. Verified end to end against a live daemon: restart while running (old pid gone, new pid serving IPC with all five modules up), restart from cold, stop, and restart over a socket left by `kill -9`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GF8cq44uC2nDHjrRNn6mWf
ThreatCrush Security Scan12 finding(s) HIGH/CRITICAL: 1 | MEDIUM: 6 | LOW: 5
Snippets are redacted; ThreatCrush never prints matched credential material. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
startandstopalready existed. The documented way to reload the daemon wasthreatcrush stop && threatcrush start, so this addsrestartas a first-class command and points the module-reload hint, the SDK README, PRD.md and the web docs page at it.Two correctness fixes fall out of doing it properly, both in the stop path:
daemonStopmisread EPERM as "the process is gone". It used a rawprocess.kill(pid, 0)and treated the throw as death, but EPERM means the opposite: the process is alive and we may not signal it. A non-root client stopping a root-owned daemon would print✓ threatcrushd stoppedwhile the daemon kept running, then delete a pidfile that was still valid. It now usesisProcessAlivefrompidfile.ts, which already handles EPERM correctly, keeps the pidfile when the daemon survives, and returns a boolean sorestartcan refuse to start a second daemon over a live socket.A SIGKILLed daemon leaves its socket behind.
daemonStart's readiness check isexistsSync(socket), so a leftover file makes it report a green checkmark for a daemon that never bound.releaseStaleSocketwaits for the file to go and unlinks it if it doesn't.Verification
Built and exercised against a live daemon on Linux, user mode:
kill -9— new daemon genuinely bound, confirmed bystatusreturning its real pid and uptime rather than the stale sockettsc --noEmitclean, 38/38 vitest passing, pre-commit hook (CLI tsup build +next build) green.🤖 Generated with Claude Code
https://claude.ai/code/session_01GF8cq44uC2nDHjrRNn6mWf