Skip to content

Commit

Permalink
fix(platform): support shutdown in Docker environment (#366)
Browse files Browse the repository at this point in the history
* Support Unix sigterm handlers

* 'Chronicle' instead of 'node'

Co-authored-by: Jochen Görtler <grtlr@users.noreply.github.com>

* Refactor shutdown module

* Remove task::spawn and channel logic from shutdown module

* Move shutdown logic to `main.rs`

Co-authored-by: Jochen Görtler <grtlr@users.noreply.github.com>
Co-authored-by: Jochen Görtler <jochen.goertler@iota.org>
  • Loading branch information
3 people authored Jul 1, 2022
1 parent 7c95e56 commit 8cead0e
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions bin/inx-chronicle/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,36 @@ async fn main() {
async fn startup(scope: &mut RuntimeScope) -> Result<(), Box<dyn Error + Send + Sync>> {
let launcher_addr = scope.spawn_actor_unsupervised(Launcher).await;

spawn_task("ctrl-c listener", async move {
tokio::signal::ctrl_c().await.ok();
spawn_task("shutdown listener", async move {
shutdown_signal_listener().await;
launcher_addr.abort().await;
});

Ok(())
}

async fn shutdown_signal_listener() {
#[cfg(unix)]
{
use futures::future;
use tokio::signal::unix::{signal, Signal, SignalKind};

// Panic: none of the possible error conditions should happen.
let mut signals = vec![SignalKind::interrupt(), SignalKind::terminate()]
.iter()
.map(|kind| signal(*kind).unwrap())
.collect::<Vec<Signal>>();
let signal_futs = signals.iter_mut().map(|signal| Box::pin(signal.recv()));
let (signal_event, _, _) = future::select_all(signal_futs).await;

if signal_event.is_none() {
panic!("Shutdown signal stream failed, channel may have closed.");
}
}
#[cfg(not(unix))]
{
if let Err(e) = tokio::signal::ctrl_c().await {
panic!("Failed to intercept CTRL-C: {:?}.", e);
}
}
}

0 comments on commit 8cead0e

Please sign in to comment.