diff options
author | Paweł Dybiec <pawel@dybiec.info> | 2022-12-27 18:21:32 +0000 |
---|---|---|
committer | Paweł Dybiec <pawel@dybiec.info> | 2022-12-27 18:21:32 +0000 |
commit | 87559a56ff51bf0a4a5f886889d2a6a64ad7f947 (patch) | |
tree | 909d1731ae8e6881275b9a1e16e893164bb1cba2 /src | |
parent | format (diff) |
Proper handling of signals
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs index bc3b8b7..6ea162b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ mod mattermost; use std::path::Path; use anyhow::anyhow; +use tokio::signal::unix; use tokio::{self}; use tracing::{debug, warn}; @@ -118,12 +119,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { .handle_websocket_stream(Vav::new(db), shutdown_recv) .await }); - match tokio::signal::ctrl_c().await { - Ok(()) => {} - Err(err) => { - eprintln!("Unable to listen for shutdown signal: {}", err); - // we also shut down in case of error - } + { + let mut sigterm = unix::signal(unix::SignalKind::terminate())?; + let mut sigint = unix::signal(unix::SignalKind::interrupt())?; + let mut sigquit = unix::signal(unix::SignalKind::quit())?; + tokio::select! { + signal = sigterm.recv() => signal, + signal = sigint.recv() => signal, + signal = sigquit.recv() => signal, + }; } shutdown_send.send(())?; websocket_task.await??; |