From de3343b04e09f4b097412ca354a6a85f089b6d12 Mon Sep 17 00:00:00 2001 From: Alexander Baranov Date: Fri, 8 May 2026 19:04:18 +0300 Subject: [PATCH] =?UTF-8?q?smart-house-web:=20=D0=B2=20=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smart-house-web/backend/Cargo.toml | 2 +- smart-house-web/backend/src/lib.rs | 1 + smart-house-web/backend/src/server.rs | 16 ++++++++++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/smart-house-web/backend/Cargo.toml b/smart-house-web/backend/Cargo.toml index 00ddd0c..fcb0467 100644 --- a/smart-house-web/backend/Cargo.toml +++ b/smart-house-web/backend/Cargo.toml @@ -7,4 +7,4 @@ edition = "2024" tracing = "0.1" tracing-subscriber = "0.3" axum = "0.8" -tokio = { version = "1.52", features = ["macros", "rt-multi-thread"] } +tokio = { version = "1.52", features = ["rt", "rt-multi-thread", "signal"] } diff --git a/smart-house-web/backend/src/lib.rs b/smart-house-web/backend/src/lib.rs index 1036c99..b24503e 100644 --- a/smart-house-web/backend/src/lib.rs +++ b/smart-house-web/backend/src/lib.rs @@ -2,6 +2,7 @@ const CODE_LOGGER_INITIALIZATION_ERROR: i32 = 1; const CODE_TOKIO_RUNTIME_CREATION_ERROR: i32 = 2; const CODE_LISTENER_BINDING_ERROR: i32 = 3; const CODE_STARTIG_SERVER_ERROR: i32 = 4; +const CODE_CTRL_C_SIGNAL_INSTALL_ERROR: i32 = 5; pub fn init_logger() { use tracing_subscriber::{Layer, layer::SubscriberExt, util::SubscriberInitExt}; diff --git a/smart-house-web/backend/src/server.rs b/smart-house-web/backend/src/server.rs index 21df591..e4695bc 100644 --- a/smart-house-web/backend/src/server.rs +++ b/smart-house-web/backend/src/server.rs @@ -1,7 +1,7 @@ -pub fn run_server() { - use std::process::exit; - use tracing::{error, info}; +use std::process::exit; +use tracing::{error, info}; +pub fn run_server() { let runtime = match tokio::runtime::Builder::new_multi_thread() .worker_threads(2) .enable_all() @@ -40,4 +40,12 @@ async fn fallback() -> axum::response::Response { (axum::http::StatusCode::NOT_FOUND, "404 NOT FOUND").into_response() } -async fn shutdown_signal() {} +async fn shutdown_signal() { + let ctrl_c = match tokio::signal::ctrl_c().await { + Ok(signal) => signal, + Err(e) => { + error!("Can't install Ctrl+C signal handler: {:?}", e); + exit(crate::CODE_CTRL_C_SIGNAL_INSTALL_ERROR); + } + }; +}