watch for SIGTERM

This commit is contained in:
Bryan Stitt 2023-07-22 02:30:49 -07:00
parent 4dfe092e08
commit e01b3c2806

View File

@ -12,9 +12,10 @@ use std::sync::atomic::AtomicU16;
use std::sync::Arc;
use std::time::Duration;
use std::{fs, thread};
use tokio::select;
use tokio::signal::unix::SignalKind;
use tokio::sync::{broadcast, mpsc, oneshot};
use tokio::time::{sleep_until, Instant};
use tokio::{select, signal};
use tracing::{error, info, trace, warn};
/// start the main proxy daemon
@ -140,6 +141,7 @@ impl ProxydSubCommand {
}
}
// TODO: wait for SIGHUP instead?
thread::sleep(Duration::from_secs(10));
});
}
@ -188,6 +190,8 @@ impl ProxydSubCommand {
let frontend_handle = flatten_handle(frontend_handle);
let mut terminate_stream = signal::unix::signal(SignalKind::terminate())?;
// if everything is working, these should all run forever
let mut exited_with_err = false;
let mut frontend_exited = false;
@ -231,6 +235,16 @@ impl ProxydSubCommand {
}
}
}
x = terminate_stream.recv() => {
match x {
Some(_) => info!("quiting from SIGTERM"),
None => {
// TODO: i don't think this is possible
error!("error quiting from SIGTERM");
exited_with_err = true;
}
}
}
// TODO: This seems to have been removed on the main branch
// TODO: how can we properly watch background handles here? this returns None immediatly and the app exits. i think the bug is somewhere else though
x = spawned_app.background_handles.next() => {