handle ctrl+c in containers
This commit is contained in:
parent
fd7f551726
commit
fd942bb416
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -1511,6 +1511,15 @@ dependencies = [
|
|||||||
"lazy_static",
|
"lazy_static",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "signal-hook-registry"
|
||||||
|
version = "1.4.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "siphasher"
|
name = "siphasher"
|
||||||
version = "0.3.11"
|
version = "0.3.11"
|
||||||
@ -1679,6 +1688,7 @@ dependencies = [
|
|||||||
"mio",
|
"mio",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
|
"signal-hook-registry",
|
||||||
"socket2",
|
"socket2",
|
||||||
"tokio-macros",
|
"tokio-macros",
|
||||||
"windows-sys 0.48.0",
|
"windows-sys 0.48.0",
|
||||||
|
@ -16,7 +16,7 @@ serde_with = "3.8.1"
|
|||||||
tera = "1.19.1"
|
tera = "1.19.1"
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
time = { workspace = true }
|
time = { workspace = true }
|
||||||
tokio = { version = "1.37.0", features = ["rt-multi-thread", "macros"] }
|
tokio = { version = "1.37.0", features = ["signal", "rt-multi-thread", "macros"] }
|
||||||
tokio-util = "0.7.11"
|
tokio-util = "0.7.11"
|
||||||
tracing = "0.1.40"
|
tracing = "0.1.40"
|
||||||
tracing-subscriber = "0.3.18"
|
tracing-subscriber = "0.3.18"
|
||||||
|
@ -12,6 +12,8 @@ use poem::{
|
|||||||
Route, Server,
|
Route, Server,
|
||||||
};
|
};
|
||||||
use rust_embed::RustEmbed;
|
use rust_embed::RustEmbed;
|
||||||
|
use tokio::signal;
|
||||||
|
use tracing::info;
|
||||||
|
|
||||||
pub mod app_state;
|
pub mod app_state;
|
||||||
pub mod cli;
|
pub mod cli;
|
||||||
@ -123,8 +125,15 @@ pub async fn run(config: Config) -> Result<(), std::io::Error> {
|
|||||||
.data(app_state)
|
.data(app_state)
|
||||||
.with(Tracing);
|
.with(Tracing);
|
||||||
|
|
||||||
Server::new(TcpListener::bind("[::]:3000"))
|
let server = Server::new(TcpListener::bind("[::]:3000"))
|
||||||
.name("cops-web")
|
.name("cops-web")
|
||||||
.run(app)
|
.run(app);
|
||||||
.await
|
|
||||||
|
tokio::select! {
|
||||||
|
_ = server => {},
|
||||||
|
_ = signal::ctrl_c() => {
|
||||||
|
info!("Received Ctrl+C, shutting down...");
|
||||||
|
},
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user