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
impl UnixGracefulShutdown
Sourcepub fn terminate_only(timeout: Duration) -> UnixGracefulShutdown
pub fn terminate_only(timeout: Duration) -> UnixGracefulShutdown
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.
Sourcepub fn interrupt_only(timeout: Duration) -> UnixGracefulShutdown
pub fn interrupt_only(timeout: Duration) -> UnixGracefulShutdown
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.
Sourcepub fn from_phases(
phases: impl IntoIterator<Item = UnixGracefulPhase>,
) -> UnixGracefulShutdown
pub fn from_phases( phases: impl IntoIterator<Item = UnixGracefulPhase>, ) -> UnixGracefulShutdown
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.
Sourcepub fn phases(&self) -> &[UnixGracefulPhase]
pub fn phases(&self) -> &[UnixGracefulPhase]
Phases in dispatch order.
Trait Implementations§
Source§impl Clone for UnixGracefulShutdown
impl Clone for UnixGracefulShutdown
Source§fn clone(&self) -> UnixGracefulShutdown
fn clone(&self) -> UnixGracefulShutdown
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for UnixGracefulShutdown
impl Debug for UnixGracefulShutdown
Source§impl PartialEq for UnixGracefulShutdown
impl PartialEq for UnixGracefulShutdown
Source§fn eq(&self, other: &UnixGracefulShutdown) -> bool
fn eq(&self, other: &UnixGracefulShutdown) -> bool
self and other values to be equal, and is used by ==.impl Eq for UnixGracefulShutdown
impl StructuralPartialEq for UnixGracefulShutdown
Auto Trait Implementations§
impl Freeze for UnixGracefulShutdown
impl RefUnwindSafe for UnixGracefulShutdown
impl Send for UnixGracefulShutdown
impl Sync for UnixGracefulShutdown
impl Unpin for UnixGracefulShutdown
impl UnsafeUnpin for UnixGracefulShutdown
impl UnwindSafe for UnixGracefulShutdown
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.