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"
|
version = "1.16.0"
|
||||||
optional = true
|
optional = true
|
||||||
|
|
||||||
|
[dependencies.tokio]
|
||||||
[target.'cfg(not(unix))'.dependencies]
|
version = "1.36.0"
|
||||||
tokio = { version = "1.36.0", features = [
|
features = [
|
||||||
"fs",
|
"fs",
|
||||||
"macros",
|
"macros",
|
||||||
"sync",
|
"sync",
|
||||||
] } # tokio signals are not used on non-*nix platforms
|
"signal",
|
||||||
|
]
|
||||||
|
|
||||||
# *nix-specific dependencies
|
# *nix-specific dependencies
|
||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
nix = { version = "0.28.0", features = ["resource"] }
|
nix = { version = "0.28.0", features = ["resource"] }
|
||||||
sd-notify = { version = "0.4.1", optional = true } # systemd is only available/relevant on *nix platforms
|
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
|
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,
|
CanonicalJsonValue, EventId, OwnedDeviceId, OwnedEventId, OwnedRoomId, OwnedUserId, RoomId, UserId,
|
||||||
};
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
#[cfg(unix)]
|
||||||
|
use tokio::signal::unix::{signal, SignalKind};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
sync::mpsc,
|
sync::mpsc,
|
||||||
time::{interval, Instant},
|
time::{interval, Instant},
|
||||||
|
@ -1083,9 +1085,6 @@ impl KeyValueDatabase {
|
||||||
|
|
||||||
#[tracing::instrument]
|
#[tracing::instrument]
|
||||||
async fn start_cleanup_task() {
|
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));
|
let timer_interval = Duration::from_secs(u64::from(services().globals.config.cleanup_second_interval));
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
|
|
24
src/main.rs
24
src/main.rs
|
@ -1,7 +1,6 @@
|
||||||
use std::{
|
#[cfg(unix)]
|
||||||
fs::Permissions, future::Future, io, net::SocketAddr, os::unix::fs::PermissionsExt, path::Path, sync::atomic,
|
use std::os::unix::fs::PermissionsExt as _;
|
||||||
time::Duration,
|
use std::{fs::Permissions, future::Future, io, net::SocketAddr, path::Path, sync::atomic, time::Duration};
|
||||||
};
|
|
||||||
|
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::{DefaultBodyLimit, FromRequestParts, MatchedPath},
|
extract::{DefaultBodyLimit, FromRequestParts, MatchedPath},
|
||||||
|
@ -25,6 +24,7 @@ use http::{
|
||||||
Method, StatusCode, Uri,
|
Method, StatusCode, Uri,
|
||||||
};
|
};
|
||||||
use hyper::Server;
|
use hyper::Server;
|
||||||
|
#[cfg(unix)]
|
||||||
use hyperlocal::SocketIncoming;
|
use hyperlocal::SocketIncoming;
|
||||||
use ruma::api::{
|
use ruma::api::{
|
||||||
client::{
|
client::{
|
||||||
|
@ -35,10 +35,9 @@ use ruma::api::{
|
||||||
};
|
};
|
||||||
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
|
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
|
||||||
use tikv_jemallocator::Jemalloc;
|
use tikv_jemallocator::Jemalloc;
|
||||||
#[cfg(unix)]
|
|
||||||
use tokio::signal;
|
|
||||||
use tokio::{
|
use tokio::{
|
||||||
sync::{oneshot, oneshot::Sender},
|
signal,
|
||||||
|
sync::oneshot::{self, Sender},
|
||||||
task::JoinSet,
|
task::JoinSet,
|
||||||
};
|
};
|
||||||
use tower::ServiceBuilder;
|
use tower::ServiceBuilder;
|
||||||
|
@ -730,21 +729,24 @@ async fn shutdown_signal(handle: ServerHandle, tx: Sender<()>) -> Result<()> {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
let terminate = async {
|
let terminate = async {
|
||||||
signal::unix::signal(signal::unix::SignalKind::terminate())
|
signal::unix::signal(signal::unix::SignalKind::terminate())
|
||||||
.expect("failed to install signal handler")
|
.expect("failed to install SIGTERM handler")
|
||||||
.recv()
|
.recv()
|
||||||
.await;
|
.await;
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(not(unix))]
|
|
||||||
let terminate = std::future::pending::<()>();
|
|
||||||
|
|
||||||
let sig: &str;
|
let sig: &str;
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
_ = ctrl_c => { sig = "Ctrl+C"; },
|
_ = ctrl_c => { sig = "Ctrl+C"; },
|
||||||
_ = terminate => { sig = "SIGTERM"; },
|
_ = terminate => { sig = "SIGTERM"; },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(unix))]
|
||||||
|
tokio::select! {
|
||||||
|
_ = ctrl_c => { sig = "Ctrl+C"; },
|
||||||
|
}
|
||||||
|
|
||||||
warn!("Received {}, shutting down...", sig);
|
warn!("Received {}, shutting down...", sig);
|
||||||
let shutdown_time_elapsed = tokio::time::Instant::now();
|
let shutdown_time_elapsed = tokio::time::Instant::now();
|
||||||
handle.graceful_shutdown(Some(Duration::from_secs(180)));
|
handle.graceful_shutdown(Some(Duration::from_secs(180)));
|
||||||
|
|
Loading…
Reference in New Issue