Skip to content

Commit

Permalink
feat(riklet): add SIGTERM signal handle
Browse files Browse the repository at this point in the history
  • Loading branch information
kalil-pelissier committed Apr 24, 2023
1 parent b84e613 commit ea51947
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion riklet/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 12 additions & 3 deletions riklet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -39,7 +41,6 @@ pub fn init_logger() -> Result<()> {
.init();
Ok(())
}
use tokio::signal;

#[tokio::main]
async fn main() -> Result<()> {
Expand All @@ -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?;
Expand Down

0 comments on commit ea51947

Please sign in to comment.