Skip to main content

UnixGracefulShutdown

Struct UnixGracefulShutdown 

Source
pub struct UnixGracefulShutdown { /* private fields */ }
Expand description

One or more graceful-shutdown phases dispatched on Unix before the implicit SIGKILL fallback.

Always followed by SIGKILL if every configured phase elapses without the child exiting.

§Choosing a sequence

Recommended for service-like children (default for most orchestrators): UnixGracefulShutdown::terminate_only. SIGTERM is the standard Unix shutdown signal: kill <pid>, systemd, K8s, Docker, runit, and supervisord all send it. Most well-behaved long-running services install a SIGTERM handler.

Recommended for CLI-like children: UnixGracefulShutdown::interrupt_only. Use when the orchestrator’s user model is “I pressed Ctrl-C” and the child is expected to handle SIGINT (Tokio tokio::signal::ctrl_c(), Python KeyboardInterrupt, and similar).

Multi-phase sequences via from_phases are NOT a way to cover children with unknown signal handlers. If phase 1 sends a signal whose handler is missing in the child, the kernel default disposition (Term) kills the child during phase 1 and later phases are never dispatched. A two-phase SIGINT -> SIGTERM sequence does not “cover both conventions”: a child that handles only SIGTERM is killed by the SIGINT phase via kernel default before its SIGTERM handler can run, and the symmetric problem occurs for SIGTERM -> SIGINT against SIGINT-only-handler children.

Use multi-phase only when you control the child and use multiple signals as distinct cooperative shutdown stages (for example: SIGINT “begin drain” followed by SIGTERM “abort drain”). For unknown or heterogeneous children, pick terminate_only or interrupt_only.

§Construction

UnixGracefulShutdown cannot be constructed empty. The implicit SIGKILL fallback is not a phase; a graceful sequence must contain at least one signal to dispatch. Use one of the named single-signal constructors, or from_phases for a multi-phase cooperative sequence.

Implementations§

Source§

impl UnixGracefulShutdown

Source

pub fn terminate_only(timeout: Duration) -> Self

Single-phase sequence sending SIGTERM only. The recommended default for service-like children; see the type-level docs for the full discussion. The implicit SIGKILL fallback runs after timeout if the child has not exited.

Source

pub fn interrupt_only(timeout: Duration) -> Self

Single-phase sequence sending SIGINT only. Use this when forwarding a Ctrl-C / TTY interrupt to a CLI-like child; see the type-level docs for the full discussion. The implicit SIGKILL fallback runs after timeout if the child has not exited.

Source

pub fn from_phases(phases: impl IntoIterator<Item = UnixGracefulPhase>) -> Self

Multi-phase sequence dispatched in iteration order. Use only for cooperative shutdown protocols against a child you control, where each signal in the sequence has a distinct handler. For unknown children pick Self::terminate_only or Self::interrupt_only instead; see the type-level docs for why a multi-phase sequence does not “cover both conventions”.

§Panics

Panics if phases produces no elements. A graceful sequence must contain at least one phase; the implicit SIGKILL fallback is not a phase.

Source

pub fn phases(&self) -> &[UnixGracefulPhase]

Phases in dispatch order.

Trait Implementations§

Source§

impl Clone for UnixGracefulShutdown

Source§

fn clone(&self) -> UnixGracefulShutdown

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UnixGracefulShutdown

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for UnixGracefulShutdown

Source§

fn eq(&self, other: &UnixGracefulShutdown) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for UnixGracefulShutdown

Source§

impl StructuralPartialEq for UnixGracefulShutdown

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Sink for T
where T: Send + 'static,