diff options
author | Ashelyn Rose <git@ashen.earth> | 2025-03-21 23:15:01 -0600 |
---|---|---|
committer | Ashelyn Rose <git@ashen.earth> | 2025-03-21 23:15:01 -0600 |
commit | b18f08e8899b5a98dd3e1f8439ad812951a04cd9 (patch) | |
tree | 613dac28974eee66b193f48402c3ecb9b0663c88 /src | |
parent | 2683366e92676abf687c37f4afea4d4d721cb059 (diff) |
Container
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index 51b2531..ea22824 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +use tokio::signal; + #[cfg(feature = "ssr")] #[tokio::main] async fn main() { @@ -26,10 +28,36 @@ async fn main() { log!("listening on http://{}", &addr); let listener = tokio::net::TcpListener::bind(&addr).await.unwrap(); axum::serve(listener, app.into_make_service()) + .with_graceful_shutdown(shutdown_signal()) .await .unwrap(); } +#[cfg(feature = "ssr")] +async fn shutdown_signal() { + let ctrl_c = async { + signal::ctrl_c() + .await + .expect("could not install SIGINT handler") + }; + + #[cfg(unix)] + let terminate = async { + signal::unix::signal(signal::unix::SignalKind::terminate()) + .expect("could not install SIGTERM handler") + .recv() + .await; + }; + + #[cfg(not(unix))] + let terminate = std::future::pending::<()>(); + + tokio::select! { + _ = ctrl_c => {}, + _ = terminate => {}, + } +} + #[cfg(not(feature = "ssr"))] pub fn main() { // no client-side main function |