From d15147abff59955ce637922a2292a9b37f5d2601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9F=83=E6=8B=89?= Date: Fri, 15 Nov 2024 20:41:50 +0800 Subject: [PATCH] fix: graceful shutdown in unix --- deploys/compose.dev.yml | 32 ------------------------------- deploys/compose.yml | 42 ----------------------------------------- src/main.rs | 9 +++++++-- src/web/router/mod.rs | 10 +++------- 4 files changed, 10 insertions(+), 83 deletions(-) delete mode 100644 deploys/compose.dev.yml delete mode 100644 deploys/compose.yml diff --git a/deploys/compose.dev.yml b/deploys/compose.dev.yml deleted file mode 100644 index 3c00073a..00000000 --- a/deploys/compose.dev.yml +++ /dev/null @@ -1,32 +0,0 @@ -version: "3.0" -services: - db: - image: postgres:alpine - restart: always - ports: - - "5432:5432" - environment: - POSTGRES_USER: cloudsdale - POSTGRES_PASSWORD: cloudsdale - POSTGRES_DB: cloudsdale - volumes: - - "./db:/var/lib/postgresql/data" - - queue: - image: nats:alpine - restart: always - ports: - - "4222:4222" - command: - - "--js" - - "--sd=/data" - volumes: - - "./queue:/data" - - cache: - image: valkey/valkey:alpine - restart: always - ports: - - "6379:6379" - volumes: - - "./cache:/data" diff --git a/deploys/compose.yml b/deploys/compose.yml deleted file mode 100644 index 060b83c2..00000000 --- a/deploys/compose.yml +++ /dev/null @@ -1,42 +0,0 @@ -version: "3.0" -services: - core: - image: elabosak233/cdsctf:main - restart: always - ports: - - "8888:8888" - volumes: - - "./application.toml:/app/application.toml:ro" - - "./assets:/app/assets" - - "./captures:/app/captures" - - "./media:/app/media" - - "./logs:/app/logs" - depends_on: - - db - - queue - - cache - - db: - image: postgres:alpine - restart: always - environment: - POSTGRES_USER: cloudsdale - POSTGRES_PASSWORD: cloudsdale - POSTGRES_DB: cloudsdale - volumes: - - "./db:/var/lib/postgresql/data" - - queue: - image: nats:alpine - restart: always - command: - - "--js" - - "--sd=/data" - volumes: - - "./queue:/data" - - cache: - image: valkey/valkey:alpine - restart: always - volumes: - - "./cache:/data" diff --git a/src/main.rs b/src/main.rs index f5913d67..f863087c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -68,12 +68,17 @@ async fn bootstrap() { async fn shutdown_signal() { let ctrl_c = async { - tokio::signal::ctrl_c().await.expect("Failed to install Ctrl+C handler"); + tokio::signal::ctrl_c() + .await + .expect("Failed to install Ctrl+C handler"); }; #[cfg(unix)] let terminate = async { - tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate()); + tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate()) + .expect("Failed to install signal handler") + .recv() + .await; }; #[cfg(not(unix))] diff --git a/src/web/router/mod.rs b/src/web/router/mod.rs index 85fcf854..677deffc 100644 --- a/src/web/router/mod.rs +++ b/src/web/router/mod.rs @@ -1,11 +1,7 @@ -use axum::{ - middleware::from_fn, - response::IntoResponse, - Router, -}; -use tower_http::{trace::TraceLayer}; +use axum::{middleware::from_fn, response::IntoResponse, Router}; +use tower_http::trace::TraceLayer; -use crate::{web::middleware}; +use crate::web::middleware; pub mod api; pub mod metric;