mirror of
https://github.com/girlbossceo/conduwuit.git
synced 2024-11-25 22:48:34 +00:00
tokio signals are actually used for CTRL+C
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
26982fbe05
commit
aec7097cd3
15
Cargo.toml
15
Cargo.toml
|
@ -282,24 +282,19 @@ optional = true
|
|||
version = "1.16.0"
|
||||
optional = true
|
||||
|
||||
|
||||
[target.'cfg(not(unix))'.dependencies]
|
||||
tokio = { version = "1.36.0", features = [
|
||||
[dependencies.tokio]
|
||||
version = "1.36.0"
|
||||
features = [
|
||||
"fs",
|
||||
"macros",
|
||||
"sync",
|
||||
] } # tokio signals are not used on non-*nix platforms
|
||||
"signal",
|
||||
]
|
||||
|
||||
# *nix-specific dependencies
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
nix = { version = "0.28.0", features = ["resource"] }
|
||||
sd-notify = { version = "0.4.1", optional = true } # systemd is only available/relevant on *nix platforms
|
||||
tokio = { version = "1.36.0", features = [
|
||||
"fs",
|
||||
"macros",
|
||||
"sync",
|
||||
"signal",
|
||||
] }
|
||||
hyperlocal = { git = "https://github.com/softprops/hyperlocal", rev = "2ee4d149644600d326559af0d2b235c945b05c04", features = ["server"] } # unix socket support
|
||||
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@ use ruma::{
|
|||
CanonicalJsonValue, EventId, OwnedDeviceId, OwnedEventId, OwnedRoomId, OwnedUserId, RoomId, UserId,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
#[cfg(unix)]
|
||||
use tokio::signal::unix::{signal, SignalKind};
|
||||
use tokio::{
|
||||
sync::mpsc,
|
||||
time::{interval, Instant},
|
||||
|
@ -1083,9 +1085,6 @@ impl KeyValueDatabase {
|
|||
|
||||
#[tracing::instrument]
|
||||
async fn start_cleanup_task() {
|
||||
#[cfg(unix)]
|
||||
use tokio::signal::unix::{signal, SignalKind};
|
||||
|
||||
let timer_interval = Duration::from_secs(u64::from(services().globals.config.cleanup_second_interval));
|
||||
|
||||
tokio::spawn(async move {
|
||||
|
|
24
src/main.rs
24
src/main.rs
|
@ -1,7 +1,6 @@
|
|||
use std::{
|
||||
fs::Permissions, future::Future, io, net::SocketAddr, os::unix::fs::PermissionsExt, path::Path, sync::atomic,
|
||||
time::Duration,
|
||||
};
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::fs::PermissionsExt as _;
|
||||
use std::{fs::Permissions, future::Future, io, net::SocketAddr, path::Path, sync::atomic, time::Duration};
|
||||
|
||||
use axum::{
|
||||
extract::{DefaultBodyLimit, FromRequestParts, MatchedPath},
|
||||
|
@ -25,6 +24,7 @@ use http::{
|
|||
Method, StatusCode, Uri,
|
||||
};
|
||||
use hyper::Server;
|
||||
#[cfg(unix)]
|
||||
use hyperlocal::SocketIncoming;
|
||||
use ruma::api::{
|
||||
client::{
|
||||
|
@ -35,10 +35,9 @@ use ruma::api::{
|
|||
};
|
||||
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
|
||||
use tikv_jemallocator::Jemalloc;
|
||||
#[cfg(unix)]
|
||||
use tokio::signal;
|
||||
use tokio::{
|
||||
sync::{oneshot, oneshot::Sender},
|
||||
signal,
|
||||
sync::oneshot::{self, Sender},
|
||||
task::JoinSet,
|
||||
};
|
||||
use tower::ServiceBuilder;
|
||||
|
@ -730,21 +729,24 @@ async fn shutdown_signal(handle: ServerHandle, tx: Sender<()>) -> Result<()> {
|
|||
#[cfg(unix)]
|
||||
let terminate = async {
|
||||
signal::unix::signal(signal::unix::SignalKind::terminate())
|
||||
.expect("failed to install signal handler")
|
||||
.expect("failed to install SIGTERM handler")
|
||||
.recv()
|
||||
.await;
|
||||
};
|
||||
|
||||
#[cfg(not(unix))]
|
||||
let terminate = std::future::pending::<()>();
|
||||
|
||||
let sig: &str;
|
||||
|
||||
#[cfg(unix)]
|
||||
tokio::select! {
|
||||
_ = ctrl_c => { sig = "Ctrl+C"; },
|
||||
_ = terminate => { sig = "SIGTERM"; },
|
||||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
tokio::select! {
|
||||
_ = ctrl_c => { sig = "Ctrl+C"; },
|
||||
}
|
||||
|
||||
warn!("Received {}, shutting down...", sig);
|
||||
let shutdown_time_elapsed = tokio::time::Instant::now();
|
||||
handle.graceful_shutdown(Some(Duration::from_secs(180)));
|
||||
|
|
Loading…
Reference in a new issue