3 Commits

Author SHA1 Message Date
78bc46c56b Close any remaining connections once the tui exits
All checks were successful
Build and deploy / Build container and manifests (push) Successful in 6m1s
2025-04-20 21:21:07 +02:00
3e726c713f Fixed stats
All checks were successful
Build and deploy / Build container and manifests (push) Successful in 5m45s
2025-04-20 20:46:31 +02:00
878df8da40 Start graceful shutdown on SIGTERM
All checks were successful
Build and deploy / Build container and manifests (push) Successful in 5m32s
2025-04-20 00:58:18 +02:00
3 changed files with 41 additions and 4 deletions

View File

@@ -19,15 +19,15 @@ pub struct Stats {
impl Stats { impl Stats {
pub fn add_connection(&self) { pub fn add_connection(&self) {
self.connections.store(1, Ordering::Relaxed); self.connections.fetch_add(1, Ordering::Relaxed);
} }
pub fn add_rx_bytes(&self, n: usize) { pub fn add_rx_bytes(&self, n: usize) {
self.rx.store(n, Ordering::Relaxed); self.rx.fetch_add(n, Ordering::Relaxed);
} }
pub fn add_tx_bytes(&self, n: usize) { pub fn add_tx_bytes(&self, n: usize) {
self.tx.store(n, Ordering::Relaxed); self.tx.fetch_add(n, Ordering::Relaxed);
} }
pub fn connections(&self) -> usize { pub fn connections(&self) -> usize {
@@ -39,7 +39,7 @@ impl Stats {
} }
pub fn set_failed(&self, failed: bool) { pub fn set_failed(&self, failed: bool) {
self.failed.store(failed, Ordering::Relaxed); self.failed.fetch_and(failed, Ordering::Relaxed);
} }
pub fn rx(&self) -> Unit { pub fn rx(&self) -> Unit {

View File

@@ -20,11 +20,28 @@ use tracing_subscriber::EnvFilter;
use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt; use tracing_subscriber::util::SubscriberInitExt;
#[cfg(unix)]
async fn sigterm() {
use tokio::signal::unix::SignalKind;
let mut sigterm =
tokio::signal::unix::signal(SignalKind::terminate()).expect("should be able to initialize");
sigterm.recv().await;
}
#[cfg(not(unix))]
async fn sigterm() {
std::future::pending::<()>().await;
}
async fn shutdown_task(token: CancellationToken) { async fn shutdown_task(token: CancellationToken) {
select! { select! {
_ = tokio::signal::ctrl_c() => { _ = tokio::signal::ctrl_c() => {
debug!("Received SIGINT"); debug!("Received SIGINT");
} }
_ = sigterm() => {
debug!("Received SIGTERM");
}
_ = token.cancelled() => { _ = token.cancelled() => {
debug!("Application called for graceful shutdown"); debug!("Application called for graceful shutdown");
} }

View File

@@ -330,6 +330,26 @@ impl russh::server::Handler for Handler {
Ok(session.channel_success(channel)?) Ok(session.channel_success(channel)?)
} }
async fn channel_close(
&mut self,
channel: ChannelId,
session: &mut Session,
) -> Result<(), Self::Error> {
if let Some(pty_channel) = self.pty_channel
&& pty_channel == channel
{
debug!("Pty channel closed");
session.disconnect(
russh::Disconnect::ByApplication,
"Remaining active connections have been closed",
"EN",
)?;
}
Ok(())
}
async fn tcpip_forward( async fn tcpip_forward(
&mut self, &mut self,
address: &str, address: &str,