Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,40 @@ async fn main() {

let addr: SocketAddr = cfg.address().unwrap();
log::info!("Running flagpole on {:?}", addr);
axum::Server::bind(&addr).serve(router.into_make_service()).await.unwrap();

axum::Server::bind(&addr)
.serve(router.into_make_service())
.with_graceful_shutdown(shutdown_signal())
.await
.unwrap();

log::info!("Server shutdown complete");
}

async fn shutdown_signal() {
let ctrl_c = async {
tokio::signal::ctrl_c().await.expect("failed to install CTRL+C signal handler");
};

#[cfg(unix)]
let terminate = async {
tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate())
.expect("failed to install SIGTERM signal handler")
.recv()
.await;
};

#[cfg(not(unix))]
let terminate = std::future::pending::<()>();

tokio::select! {
_ = ctrl_c => {
log::info!("Received SIGINT (CTRL+C), initiating graceful shutdown");
},
_ = terminate => {
log::info!("Received SIGTERM, initiating graceful shutdown");
},
}
}

#[derive(Clone)]
Expand Down
2 changes: 1 addition & 1 deletion tests/health_check.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use axum::Router;
use axum::body::Body;
use axum::http::{Request, StatusCode};
use axum::routing::get;
use axum::Router;
use std::sync::{Arc, RwLock};
use tower::ServiceExt;

Expand Down
Loading