This commit is contained in:
2026-01-11 13:56:40 +01:00
parent df1cdc0303
commit f7c975a3f0
2 changed files with 30 additions and 0 deletions

View File

@@ -49,6 +49,18 @@ impl App {
pub async fn run(&self) {
println!("Application démarrée. Appuyez sur Ctrl+C pour arrêter.");
// On définit les signaux d'arrêt selon la plateforme
#[cfg(unix)]
let terminate = async {
tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate())
.expect("failed to install signal handler")
.recv()
.await;
};
#[cfg(not(unix))]
let terminate = std::future::pending::<()>();
// Le select arbitre la course
tokio::select! {
// Branche 1 : Le serveur tourne. S'il crash ou finit (peu probable), on sort.
@@ -65,6 +77,10 @@ impl App {
_ = tokio::signal::ctrl_c() => {
println!("Signal d'arrêt reçu !");
}
_ = terminate => {
println!("Signal SIGTERM reçu (Docker stop) !");
}
}
println!("Nettoyage et fermeture de l'application.");