From d3447e397aec802d544b2766a67de665bb6d8198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20=C3=96sterberg?= Date: Wed, 4 Feb 2026 00:01:18 +0100 Subject: [PATCH 1/3] chore: Format log message --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index d452585..621b2a7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -85,7 +85,7 @@ async fn put_flag( let updated: bool = state.0.db.write().unwrap().set_value(&namespace, flag.clone()).unwrap(); if updated { #[cfg(feature = "logging")] - log::info!("Flag {flag} enabled in namespace {namespace}"); + log::info!("Flag '{flag}' enabled in namespace <<{namespace}>>"); } StatusCode::NO_CONTENT } From 90150bb2bf224c71722f5e2be4a953ee8e171c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20=C3=96sterberg?= Date: Wed, 4 Feb 2026 00:04:58 +0100 Subject: [PATCH 2/3] style: Format code --- rustfmt.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rustfmt.toml b/rustfmt.toml index a488b2a..8f6b35b 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -23,7 +23,7 @@ reorder_imports=true reorder_modules=true single_line_if_else_max_width=80 space_after_colon=true -spaces_before_color=false +space_before_colon=false spaces_around_ranges=false tab_spaces=4 trailing_comma="Vertical" From 35dcc090f9da37ebeee235f8fe2574738ca27278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20=C3=96sterberg?= Date: Wed, 4 Feb 2026 09:55:59 +0100 Subject: [PATCH 3/3] feat: Handle SIGINT/SIGTERM --- src/main.rs | 35 ++++++++++++++++++++++++++++++++++- tests/health_check.rs | 2 +- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 414b79d..3244a20 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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)] diff --git a/tests/health_check.rs b/tests/health_check.rs index 6e1e2f0..317ed73 100644 --- a/tests/health_check.rs +++ b/tests/health_check.rs @@ -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;