salvo-graceful-shutdown
Implement graceful server shutdown to handle in-flight requests before stopping. Use for zero-downtime deployments and proper resource cleanup.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Implement graceful server shutdown to handle in-flight requests before stopping. Use for zero-downtime deployments and proper resource cleanup.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
| name | salvo-graceful-shutdown |
| description | Implement graceful server shutdown to handle in-flight requests before stopping. Use for zero-downtime deployments and proper resource cleanup. |
| version | 0.89.3 |
| tags | ["operations","shutdown","deployment"] |
This skill helps implement graceful server shutdown in Salvo applications.
[dependencies]
salvo = "0.89.3"
tokio = { version = "1", features = ["full", "signal"] }
use salvo::prelude::*;
use salvo::server::ServerHandle;
use tokio::signal;
#[handler]
async fn hello() -> &'static str {
"Hello, World!"
}
#[tokio::main]
async fn main() {
let router = Router::new().get(hello);
let acceptor = TcpListener::new("0.0.0.0:8080").bind().await;
let server = Server::new(acceptor);
let handle = server.handle();
tokio::spawn(listen_shutdown_signal(handle));
server.serve(router).await;
}
async fn listen_shutdown_signal(handle: ServerHandle) {
let ctrl_c = async {
signal::ctrl_c()
.await
.expect("failed to install Ctrl+C handler");
};
#[cfg(unix)]
let terminate = async {
signal::unix::signal(signal::unix::SignalKind::terminate())
.expect("failed to install signal handler")
.recv()
.await;
};
#[cfg(windows)]
let terminate = async {
signal::windows::ctrl_c()
.expect("failed to install signal handler")
.recv()
.await;
};
tokio::select! {
_ = ctrl_c => println!("Received Ctrl+C, shutting down..."),
_ = terminate => println!("Received terminate signal, shutting down..."),
};
handle.stop_graceful(None);
}
use std::time::Duration;
use salvo::server::ServerHandle;
async fn listen_shutdown_signal(handle: ServerHandle) {
tokio::signal::ctrl_c().await.unwrap();
println!("Shutting down, waiting up to 30 seconds for in-flight requests...");
handle.stop_graceful(Some(Duration::from_secs(30)));
}
use salvo::prelude::*;
use std::sync::atomic::{AtomicBool, Ordering};
static SHUTTING_DOWN: AtomicBool = AtomicBool::new(false);
#[handler]
async fn health_check(res: &mut Response) {
if SHUTTING_DOWN.load(Ordering::Relaxed) {
res.status_code(StatusCode::SERVICE_UNAVAILABLE);
res.render(Json(serde_json::json!({
"status": "shutting_down",
"message": "Server is shutting down"
})));
} else {
res.render(Json(serde_json::json!({
"status": "healthy"
})));
}
}
async fn listen_shutdown_signal(handle: salvo::server::ServerHandle) {
tokio::signal::ctrl_c().await.unwrap();
SHUTTING_DOWN.store(true, Ordering::Relaxed);
println!("Marked as shutting down, waiting for traffic to drain...");
tokio::time::sleep(std::time::Duration::from_secs(5)).await;
println!("Stopping server...");
handle.stop_graceful(Some(std::time::Duration::from_secs(30)));
}
#[tokio::main]
async fn main() {
let router = Router::new()
.push(Router::with_path("health").get(health_check))
.push(Router::with_path("api/{**rest}").get(api_handler));
let acceptor = TcpListener::new("0.0.0.0:8080").bind().await;
let server = Server::new(acceptor);
let handle = server.handle();
tokio::spawn(listen_shutdown_signal(handle));
server.serve(router).await;
}
use salvo::prelude::*;
use salvo::server::ServerHandle;
use std::time::Duration;
async fn kubernetes_shutdown(handle: ServerHandle) {
#[cfg(unix)]
{
use tokio::signal::unix::{SignalKind, signal};
let mut sigterm = signal(SignalKind::terminate())
.expect("failed to install SIGTERM handler");
sigterm.recv().await;
println!("SIGTERM received from Kubernetes");
}
#[cfg(windows)]
{
tokio::signal::ctrl_c().await.unwrap();
println!("Shutdown signal received");
}
handle.stop_graceful(Some(Duration::from_secs(25)));
}
#[tokio::main]
async fn main() {
let router = Router::new().get(handler);
let acceptor = TcpListener::new("0.0.0.0:8080").bind().await;
let server = Server::new(acceptor);
let handle = server.handle();
tokio::spawn(kubernetes_shutdown(handle));
server.serve(router).await;
}
Guide for using RBatis v4 Rust ORM framework. Use when implementing database CRUD operations, writing dynamic SQL with py_sql or html_sql macros, configuring database connections, managing transactions, implementing interceptors, syncing table structures, or integrating RBatis into Genies microservices. Also use when the user asks about RBatis usage patterns, query building, or database operations in Rust.
Genies 前后端接口规范。Use when designing API contracts, defining field naming conventions, date/time formats, response models, pagination, error handling, or ID strategies between Genies backend and frontend (Web/Android/OHOS).
Guide for using flyway-rs database migration framework with RBatis. Use when implementing database schema migrations, managing SQL changelog files, configuring migration runners, handling multi-database migrations, or integrating database versioning into Genies microservices.
Guide for developing Rust microservices using Genies framework following Java DDD layering principles. Use when creating new microservices, designing aggregate roots, implementing domain events, organizing service layers, setting up Flyway migrations, or structuring a DDD-based Genies project.
Genies framework unified skill hub. Use when you need to find the right skill for any Genies framework task, including authentication, authorization, caching, configuration, database, DDD microservices, Dapr messaging, macros, K8s deployment, testing, API conventions, gateway proxy, or Salvo web framework features. Also use when the user asks about Genies framework capabilities, asks which skill to use, or wants a quick overview of available Genies skills.
Guide for using the Genies Rust microservice framework with DDD and Dapr. Use when developing with Genies, creating aggregates, domain events, Dapr subscriptions, Casbin field-level permissions, configuration management, or when the user asks about Genies framework usage patterns.