signals
This commit is contained in:
3 files changed
+41
-2
No files matched your search
Generated
+21
@@ -416,6 +416,16 @@ version = "1.0.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826"
|
checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "errno"
|
||||||
|
version = "0.3.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "etcetera"
|
name = "etcetera"
|
||||||
version = "0.11.0"
|
version = "0.11.0"
|
||||||
@@ -1284,6 +1294,16 @@ version = "2.0.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
|
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "signal-hook-registry"
|
||||||
|
version = "1.4.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b"
|
||||||
|
dependencies = [
|
||||||
|
"errno",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "slab"
|
name = "slab"
|
||||||
version = "0.4.12"
|
version = "0.4.12"
|
||||||
@@ -1591,6 +1611,7 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
"mio",
|
"mio",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
|
"signal-hook-registry",
|
||||||
"socket2",
|
"socket2",
|
||||||
"tokio-macros",
|
"tokio-macros",
|
||||||
"windows-sys",
|
"windows-sys",
|
||||||
|
|||||||
+1
-1
@@ -14,5 +14,5 @@ pulldown-cmark = { version = "0.9.6", default-features = false }
|
|||||||
rand = "0.10.3"
|
rand = "0.10.3"
|
||||||
serde = { version = "1.0.229", features = ["derive"] }
|
serde = { version = "1.0.229", features = ["derive"] }
|
||||||
sqlx = { version = "0.9.0", features = ["runtime-tokio", "sqlite"] }
|
sqlx = { version = "0.9.0", features = ["runtime-tokio", "sqlite"] }
|
||||||
tokio = { version = "1.54.1", features = ["rt-multi-thread"] }
|
tokio = { version = "1.54.1", features = ["rt-multi-thread", "signal"] }
|
||||||
tower-http = { version = "0.7.1", features = ["fs"] }
|
tower-http = { version = "0.7.1", features = ["fs"] }
|
||||||
+19
-1
@@ -53,6 +53,24 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let port = std::env::var("PORT").unwrap_or_else(|_| "3000".to_owned());
|
let port = std::env::var("PORT").unwrap_or_else(|_| "3000".to_owned());
|
||||||
let listener = TcpListener::bind(format!("0.0.0.0:{port}")).await?;
|
let listener = TcpListener::bind(format!("0.0.0.0:{port}")).await?;
|
||||||
println!("Listening on http://localhost:{port}");
|
println!("Listening on http://localhost:{port}");
|
||||||
serve(listener, app).await?;
|
serve(listener, app)
|
||||||
|
.with_graceful_shutdown(shutdown_signal())
|
||||||
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn shutdown_signal() {
|
||||||
|
let terminate = async {
|
||||||
|
tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate())
|
||||||
|
.expect("Failed to install SIGTERM handler")
|
||||||
|
.recv()
|
||||||
|
.await;
|
||||||
|
};
|
||||||
|
|
||||||
|
tokio::select! {
|
||||||
|
result = tokio::signal::ctrl_c() => {
|
||||||
|
result.expect("Failed to install Ctrl+C handler");
|
||||||
|
}
|
||||||
|
_ = terminate => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user