Feature: Container mode (--pid1) for multi-process Docker images #303
Replies: 1 comment
-
|
I think both
After a quick search I found that when pitchfork receives a SIGTERM, it'll gracefully shutdown all active daemons like below? (at least from the code) If the actual behaviour is not this, I'll dive into this to check out why. async fn handle_signal(&self) {
info!("received signal, stopping");
self.close().await;
exit(0)
}
pub(crate) async fn close(&self) {
for daemon in self.active_daemons().await {
if daemon.id == pitchfork_id { continue; }
if let Err(err) = self.stop(&daemon.id).await {
error!("failed to stop daemon {daemon}: {err}");
}
}
// ...
} Overall this is a great FR and I'll work on this later. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Pitchfork is already the best cross-platform Rust daemon manager available. With a small
--container/--pid1flag it could also replace s6-overlay as the go-to supervisor inside multi-process Docker images — something no other Rust project currently does well.What's already there
The groundwork is solid:
dependsfor ordered startupready.http/ready.delay/ready_cmdfor true readiness (better UX than s6's fd-based protocol)setsid()+killpg()for process-group shutdownWhat's missing for container/PID1 use
When pitchfork runs as PID 1 inside a Docker container two things break:
1. Zombie reaping
PID 1 must call
waitpid(-1, WNOHANG)on everySIGCHLDto reap orphaned processes (children whose parent exited before them). Without this, zombie entries accumulate in the process table indefinitely.2. SIGTERM forwarding on docker stop
Docker sends
SIGTERMto PID 1. Currently that kills pitchfork without giving daemons a chance to shut down cleanly. In container mode,SIGTERMto PID 1 should trigger the normal graceful shutdown sequence (SIGTERM to process groups → grace period → SIGKILL).Proposed API
Or as a CLI flag:
pitchfork supervisor run --containerWhen
container = true:SIGCHLDhandler that reaps all children, not just direct onesSIGTERM/SIGINTto the graceful shutdown sequenceReal-world use case
United Manufacturing Hub (open-source Industrial IoT platform used in production by Böllhoff, HiPP, Edeka) runs a single Docker container with three processes: a Go agent, Benthos streaming engine, and Redpanda broker. They currently use s6-overlay in C. Pitchfork with container mode would be a drop-in replacement with far better DX and cross-platform support.
Implementation notes
The
nixcrate already has everything needed:waitpid,WaitPidFlag,Signal,sigaction. Core addition:Plus routing
SIGTERMthrough the existing graceful shutdown path.Happy to help test or contribute a PR.
Beta Was this translation helpful? Give feedback.
All reactions