diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-11-15 18:57:04 +0100 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-11-15 18:57:04 +0100 |
commit | fedf1f952914651862395e2efca626e75b0d0d44 (patch) | |
tree | 0e967773a8e8f28af4c1c420a3a08ce546c44efc /src | |
parent | 3d7f92e5f182d798157be72773cd2775b54f172e (diff) |
shut down properly on SIGTERM
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 6 | ||||
-rw-r--r-- | src/supervisor.rs | 12 |
2 files changed, 15 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs index 14a9e46..ca39ce8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -85,8 +85,10 @@ async fn main() -> Result<()> { } } result = &mut join_handle => { - result??; // This always fails, the task never exits with an Ok(_). - unreachable!("Client::run exited successfully") + result??; + + println!("[info] <> exiting"); + return Ok(()); } } } diff --git a/src/supervisor.rs b/src/supervisor.rs index d35bbcf..805025b 100644 --- a/src/supervisor.rs +++ b/src/supervisor.rs @@ -9,6 +9,7 @@ use std::time::Duration; use std::{io, mem}; use tokio::io::unix::AsyncFd; +use tokio::signal::unix::{signal, SignalKind}; use tokio::sync::mpsc; use tokio::time::Interval; @@ -255,7 +256,7 @@ impl Client { } /// Tries to keep a session open at all costs. - /// Blocks the caller forever unless a panic occurs. + /// Blocks the caller forever unless a panic occurs or SIGTERM is received. /// /// # Arguments /// @@ -273,6 +274,8 @@ impl Client { let mut link_buf = [0; 1494]; let mut net_buf = [0; 1494]; + let mut sigterm = signal(SignalKind::terminate())?; + let mut echo_timeout = tokio::time::interval(Duration::from_secs(12)); let mut ncp_check = tokio::time::interval(Duration::from_secs(20)); @@ -299,6 +302,13 @@ impl Client { tokio::select! { biased; + _ = sigterm.recv() => { + self.lcp.close(); + + println!("[info] <> disconnect: sigterm"); + return Ok(()); + } + packet = self.pppoe.to_send() => self.send_pppoe(&sock_disc, packet).await?, packet = self.lcp.to_send() => self.send_lcp( session_fds.as_mut().map(|fds| fds.link()), |