generalbots/botserver/src/main_module/shutdown.rs
Rodrigo Rodriguez (Pragmatismo) eea9b24ef0
Some checks failed
Botlib CI / build (push) Successful in 9s
BotServer CI / build (push) Successful in 3m52s
Bottest CI / build (push) Failing after 8s
fix: CI failures - shutdown hang, bottest compile errors, botui deploy
- Add shutdown tracing and 15s forced exit to prevent SIGTERM hangs
- Fix E0583: remove self-referential mod declarations in bottest integration files
- Fix E0599: correct .status() call on Result in performance.rs
- Fix botui CI deploy: use systemctl stop/start instead of pkill+nohup
- Update PROD.md with DB-driven CI log retrieval method
2026-04-22 11:25:05 +00:00

55 lines
1.6 KiB
Rust

//! Shutdown signal handling
use log::{error, info, warn};
pub fn print_shutdown_message() {
println!();
println!("Thank you for using General Bots!");
println!();
}
pub async fn shutdown_signal() {
info!("Shutdown signal handler installed, waiting for SIGINT or SIGTERM...");
let ctrl_c = async {
if let Err(e) = tokio::signal::ctrl_c().await {
error!("Failed to install Ctrl+C handler: {}", e);
}
};
#[cfg(unix)]
let terminate = async {
match tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate()) {
Ok(mut signal) => {
info!("SIGTERM handler installed successfully");
signal.recv().await;
}
Err(e) => {
error!("Failed to install SIGTERM handler: {}", e);
}
}
};
#[cfg(not(unix))]
let terminate = std::future::pending::<()>();
tokio::select! {
_ = ctrl_c => {
info!("Received SIGINT (Ctrl+C), initiating graceful shutdown...");
}
_ = terminate => {
info!("Received SIGTERM (systemctl stop), initiating graceful shutdown...");
}
}
info!("Shutdown signal received - server will stop accepting new connections");
warn!("Graceful shutdown timeout is 10s for HTTPS, after which process will exit");
print_shutdown_message();
tokio::spawn(async {
tokio::time::sleep(std::time::Duration::from_secs(15)).await;
warn!("Graceful shutdown exceeded 15s - forcing process exit to prevent hang");
std::process::exit(0);
});
}