pub struct GracefulShutdown {
pub unix: UnixGracefulShutdown,
}Expand description
Per-platform graceful-shutdown policy passed to ProcessHandle::terminate and related APIs.
Carries a sequence of one or more graceful-shutdown signals to dispatch before falling back to the implicit forceful kill. The shape is platform-conditional because the available graceful-shutdown signals themselves are platform-conditional:
- On Unix it carries a
UnixGracefulShutdownof one or moreUnixGracefulPhases. - On Windows it carries a single
WindowsGracefulShutdowntimeout for the only available graceful signal,CTRL_BREAK_EVENT.
SIGKILL on Unix and TerminateProcess on Windows are always the implicit final fallback;
they are not configurable phases.
§Choosing the Unix sequence
See UnixGracefulShutdown for the recommended single-signal sequences and a discussion of
why mixing SIGINT and SIGTERM does not cover children with unknown signal handlers.
§Cross-platform construction
Use GracefulShutdown::builder to write a single cross-platform construction expression.
The setter for the platform that does not match the current target accepts its argument
without using it, so no cfg gates are needed at the call site:
use std::time::Duration;
use tokio_process_tools::GracefulShutdown;
// Common case: single-signal sequences via the convenience shortcuts.
let shutdown = GracefulShutdown::builder()
.unix_sigterm(Duration::from_secs(10))
.windows_ctrl_break(Duration::from_secs(10))
.build();For the rare multiphase case, use the GracefulShutdownBuilder::unix setter, accepting a
custom-built UnixGracefulShutdown:
use std::time::Duration;
use tokio_process_tools::{
GracefulShutdown, UnixGracefulPhase, UnixGracefulShutdown,
};
let shutdown = GracefulShutdown::builder()
.unix(UnixGracefulShutdown::from_phases([
UnixGracefulPhase::interrupt(Duration::from_secs(60)),
UnixGracefulPhase::terminate(Duration::from_secs(5)),
]))
.windows_ctrl_break(Duration::from_secs(10))
.build();§Platform availability
This type is only available on Unix and Windows because the underlying graceful-shutdown
signals only exist there. On other Tokio-supported targets the spawn, wait, output-collection,
and ProcessHandle::kill APIs remain available; only the graceful-termination surface
(terminate(...), terminate_on_drop(...), wait_for_completion_or_terminate(...), the
send_*_signal(...) methods, and this type) is gated out.
Fields§
§unix: UnixGracefulShutdownUnix graceful-shutdown phase sequence.
Implementations§
Source§impl GracefulShutdown
impl GracefulShutdown
Sourcepub fn builder() -> GracefulShutdownBuilder<UnixUnset>
pub fn builder() -> GracefulShutdownBuilder<UnixUnset>
Trait Implementations§
Source§impl Clone for GracefulShutdown
impl Clone for GracefulShutdown
Source§fn clone(&self) -> GracefulShutdown
fn clone(&self) -> GracefulShutdown
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 GracefulShutdown
impl Debug for GracefulShutdown
Source§impl PartialEq for GracefulShutdown
impl PartialEq for GracefulShutdown
Source§fn eq(&self, other: &GracefulShutdown) -> bool
fn eq(&self, other: &GracefulShutdown) -> bool
self and other values to be equal, and is used by ==.impl Eq for GracefulShutdown
impl StructuralPartialEq for GracefulShutdown
Auto Trait Implementations§
impl Freeze for GracefulShutdown
impl RefUnwindSafe for GracefulShutdown
impl Send for GracefulShutdown
impl Sync for GracefulShutdown
impl Unpin for GracefulShutdown
impl UnsafeUnpin for GracefulShutdown
impl UnwindSafe for GracefulShutdown
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.