diff --git a/riklet/src/core.rs b/riklet/src/core.rs index 51cbd7b..ee00d23 100644 --- a/riklet/src/core.rs +++ b/riklet/src/core.rs @@ -212,7 +212,7 @@ impl Riklet { pub async fn shutdown(&mut self) -> Result<()> { info!("Clean Riklet state."); - // clean global iptables rules + // Delete general network configuration let global_runtime_network = GlobalRuntimeNetwork::new(); global_runtime_network .destroy() diff --git a/riklet/src/main.rs b/riklet/src/main.rs index 8ec98bf..079cf76 100644 --- a/riklet/src/main.rs +++ b/riklet/src/main.rs @@ -10,7 +10,9 @@ mod structs; use crate::core::Riklet; use anyhow::Result; -use tracing::{error, metadata::LevelFilter}; +use tokio::signal::ctrl_c; +use tokio::signal::unix::{signal, SignalKind}; +use tracing::{error, info, metadata::LevelFilter}; use tracing_subscriber::{ fmt, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, EnvFilter, }; @@ -39,7 +41,6 @@ pub fn init_logger() -> Result<()> { .init(); Ok(()) } -use tokio::signal; #[tokio::main] async fn main() -> Result<()> { @@ -59,9 +60,17 @@ async fn main() -> Result<()> { std::process::exit(2); }); + // An infinite stream of hangup signals. + let mut signals = signal(SignalKind::terminate())?; + tokio::select! { _ = riklet.run() => {}, - _ = signal::ctrl_c() => {} + _ = ctrl_c() => { + info!("Receive SIGINT signal.") + }, + _ = signals.recv() => { + info!("Receive SIGTERM signal.") + } } riklet.shutdown().await?;