diff --git a/riklet/src/core.rs b/riklet/src/core.rs index 0155b22f..3be7cc6d 100644 --- a/riklet/src/core.rs +++ b/riklet/src/core.rs @@ -212,14 +212,14 @@ impl Riklet { pub async fn shutdown(&self) -> Result<()> { info!("Clean Riklet state"); - // clean global iptables rules + // Delete general network configuration let global_runtime_network = GlobalRuntimeNetwork::new(); global_runtime_network .destroy() .await .map_err(RikletError::NetworkError)?; - //clean all runtime + // Stop and clean all runtime for (_, runtime) in &self.runtimes { runtime .down() diff --git a/riklet/src/main.rs b/riklet/src/main.rs index 62aac0a2..e3c8fc96 100644 --- a/riklet/src/main.rs +++ b/riklet/src/main.rs @@ -13,8 +13,9 @@ use crate::core::Riklet; use crate::utils::init_logger; use anyhow::Result; -use tokio::signal; -use tracing::error; +use tokio::signal::ctrl_c; +use tokio::signal::unix::{signal, SignalKind}; +use tracing::{error, info}; #[tokio::main] async fn main() -> Result<()> { @@ -34,9 +35,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?;