Listen to SIGTERM in addition to ctrl-c for graceful shutdown

This commit is contained in:
Antonio Scandurra 2022-12-13 23:03:04 +01:00
parent 7824ace58b
commit 34b69896e4
2 changed files with 10 additions and 3 deletions

View file

@ -1,3 +1,3 @@
ZED_ENVIRONMENT=preview
RUST_LOG=debug
RUST_LOG=info
INVITE_LINK_PREFIX=https://zed.dev/invites/

View file

@ -7,6 +7,7 @@ use std::{
net::{SocketAddr, TcpListener},
path::Path,
};
use tokio::signal::unix::SignalKind;
use tracing_log::LogTracer;
use tracing_subscriber::{filter::EnvFilter, fmt::format::JsonFields, Layer};
use util::ResultExt;
@ -66,9 +67,15 @@ async fn main() -> Result<()> {
axum::Server::from_tcp(listener)?
.serve(app.into_make_service_with_connect_info::<SocketAddr>())
.with_graceful_shutdown(async move {
tokio::signal::ctrl_c()
.await
let mut sigterm = tokio::signal::unix::signal(SignalKind::terminate())
.expect("failed to listen for interrupt signal");
let mut sigint = tokio::signal::unix::signal(SignalKind::interrupt())
.expect("failed to listen for interrupt signal");
let sigterm = sigterm.recv();
let sigint = sigint.recv();
futures::pin_mut!(sigterm);
futures::pin_mut!(sigint);
futures::future::select(sigterm, sigint).await;
tracing::info!("Received interrupt signal");
rpc_server.teardown();
})