diff options
| author | tv <tv@krebsco.de> | 2026-10-21 14:15:55 +0200 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-21 14:15:55 +0200 |
| commit | 02f9291aeb1b29a5e9349e9eef361431b2a41f12 (patch) | |
| tree | 84380812418e7eb71f13a46b071e1314506e2c1d /src/main.rs | |
| parent | f0e37237004188e761da9730e24b11fc162bec8b (diff) | |
handle SIGTERM
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index ab91490..2b90bef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -226,6 +226,9 @@ async fn main() -> Result<()> { let server_fut = server_builder.into_future(); tokio::pin!(server_fut); + let mut terminate = tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate()) + .context("Installing the SIGTERM handler")?; + tokio::select! { exit_status = state.transport.wait_for_exit() => { error!("Mycelium runtime process exited. Status: {:?}", exit_status); @@ -247,6 +250,14 @@ async fn main() -> Result<()> { let _ = shutdown_tx.send(()); let _ = server_fut.as_mut().await; } + + // What service managers send; handled like Ctrl-C so the supervised Mycelium is + // stopped on the way out instead of relying on the kernel's parent-death signal. + _ = terminate.recv() => { + info!("Received termination signal. Shutting down..."); + let _ = shutdown_tx.send(()); + let _ = server_fut.as_mut().await; + } } info!("HTTP API server stopped"); |
