feat(headless): handle SIGTERM/SIGHUP for graceful shutdown#124
feat(headless): handle SIGTERM/SIGHUP for graceful shutdown#124
Conversation
Enable ctrlc's "termination" feature so the signal handler also triggers on SIGTERM and SIGHUP. This enables clean shutdown (PID file removal, socket cleanup) from systemd stop, docker stop, and nohup hangup. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR extends arf headless shutdown handling so that process termination signals (SIGTERM/SIGHUP) trigger the same graceful shutdown path as Ctrl+C, enabling clean cleanup (PID file + IPC socket/session) when managed by systemd/docker/nohup.
Changes:
- Enable
ctrlc’sterminationfeature to handle SIGTERM/SIGHUP in addition to SIGINT. - Update headless startup comments to reflect expanded signal handling behavior.
- Add a Unix-only integration test asserting SIGTERM causes graceful exit and PID file removal.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/arf-console/tests/headless_tests.rs | Adds SIGTERM integration test for graceful shutdown + PID file cleanup. |
| crates/arf-console/src/main.rs | Documents that the existing shutdown handler now covers SIGTERM/SIGHUP (via ctrlc feature). |
| Cargo.toml | Enables ctrlc crate termination feature at the workspace level. |
| CHANGELOG.md | Documents the new graceful shutdown behavior on SIGTERM/SIGHUP. |
Comments suppressed due to low confidence (1)
crates/arf-console/src/main.rs:494
- The warning log still says "Could not set Ctrl+C handler" even though the handler is now used for SIGTERM/SIGHUP as well (via the termination feature). Updating the message to refer to a generic signal/shutdown handler would avoid misleading logs when SIGTERM/SIGHUP handling is the reason this path exists.
// Set up signal handler for graceful shutdown.
// With the "termination" feature, ctrlc also handles SIGTERM and SIGHUP,
// enabling clean shutdown from systemd stop, docker stop, nohup hangup, etc.
let shutdown_signal = shutdown.clone();
if let Err(e) = ctrlc::set_handler(move || {
shutdown_signal.store(true, Ordering::Release);
}) {
log::warn!("Could not set Ctrl+C handler: {}", e);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Wait for "Headless mode ready" stderr message (printed after the ctrlc handler is installed) instead of just the PID file, to avoid a race where SIGTERM arrives before the handler is set up. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…exit detection - Extract common signal test logic into assert_signal_graceful_shutdown helper - Add SIGHUP test alongside SIGTERM - Check try_wait() in readiness loop for early-exit fail-fast with diagnostics - wait_for_exit now returns ExitStatus; tests assert clean exit code - Include server output in panic messages for easier debugging Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
terminationfeature so the existing signal handler also triggers on SIGTERM and SIGHUPsystemd stop,docker stop, and nohup hangupTest plan
test_headless_sigterm_shutdown— sends SIGTERM and verifies graceful exit + PID file removalarf headless --pid-file /tmp/arf.pidthenkill <pid>— verify clean exit and PID file removeddocker stopon containerized arf headless — verify clean exit🤖 Generated with Claude Code