shep-daemon 0.25.2

The supervision engine behind shep: process spawning, restart policy, the log plane, watch and cron restarts, and the RPC server
Documentation
//! Real [`crate::runner::ProcessRunner`] over actual OS processes.
//!
//! Split by concern: `runner` holds `TokioRunner` and `TokioProc` and their
//! trait impls, `log_file` is the buffered per-stream log writer, `preflight`
//! judges a program before a spawn, and `pump` holds the tasks that drain a
//! child's stdout, stderr and shepherd channel.

use core::time::Duration;

/// Capacity of every channel a spawn wires up: enough that a bursty child
/// does not back-pressure a sheep task that is merely slow to poll, without
/// buffering unboundedly.
const CHANNEL_CAPACITY: usize = 32;

/// Bytes a log file buffers before the pump writes them through.
///
/// `tokio::fs::File` hands every `write` to the blocking pool: 32.8 us of
/// daemon CPU per line against 0.99 us for the `write(2)` under it. Batching
/// amortises one dispatch over a whole buffer.
const LOG_BUFFER: usize = 8 * 1024;

/// How long a line may sit in that buffer before the pump writes it out
/// anyway.
///
/// Timed from the oldest unflushed line, so a steady trickle cannot push the
/// deadline out indefinitely. It exists for the sheep that logs one line and
/// then goes quiet.
const IDLE_FLUSH: Duration = Duration::from_millis(50);

/// Bytes each stream's reader may hold ahead of the lines it has emitted.
///
/// Two bounds rest on it: the most a handover can strand in userspace, since
/// bytes taken off the pipe die with the image at the `execve`, and the most
/// [`pump::drain_ready`] can write.
#[cfg(unix)]
const READ_BUFFER: usize = 8 * 1024;

/// How long the pump keeps reading after its sheep task has let go.
///
/// Without it [`pump::spawn_log_pump`]'s `select!` can take the
/// `logs_tx.closed()` branch with the child's last line still in the pipe:
/// `tokio::select!` picks between ready branches at random. The budget is
/// spent only when a lamb still holds a write end, and it does not bound the
/// lamb. 100ms against a worst case of 7 to 12ms for two full pipes.
const FINAL_DRAIN: Duration = Duration::from_millis(100);

#[cfg(unix)]
mod ansi;
#[cfg(unix)]
mod dog_link;
mod line_reader;
mod log_file;
mod preflight;
#[cfg(unix)]
mod pty;
mod pump;
mod runner;
#[cfg(windows)]
mod windows_pipe;

#[cfg(test)]
mod tests;

pub use runner::{TokioProc, TokioRunner};

pub(crate) use log_file::{open_append, record_lock};
#[cfg(unix)]
pub(crate) use runner::signal_group;
pub(crate) use runner::signal_pid;