Skip to content

Commit

Permalink
system: handle SIGTERM signals
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfelton committed Aug 19, 2024
1 parent 259de8b commit ef878ee
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ rand_core = "0.6.4"
log = "0.4.17"
log4rs = { version = "1.2.0", features = ["file_appender"] }
rcgen = { version = "0.13.1", features = ["pem", "x509-parser"] }
tokio = { version = "1.25.0", features = ["rt", "rt-multi-thread"] }
tokio = { version = "1.25.0", features = ["rt", "rt-multi-thread", "signal"] }
tonic = { version = "0.11", features = [ "tls", "transport" ] }
tonic_lnd = { git = "https://github.com/orbitalturtle/tonic_lnd", rev="18c5a71084886024a6b90307bfb8822288c5daea", package="fedimint-tonic-lnd", features = ["lightningrpc", "routerrpc", "versionrpc"] }
hex = "0.4.3"
Expand Down
15 changes: 14 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ use std::fs::create_dir_all;
use std::path::PathBuf;
use std::process::exit;
use std::sync::Arc;
use tokio::select;
use tokio::{
select,
signal::unix::{signal, SignalKind},
};
use tonic::transport::{Server, ServerTlsConfig};
use tonic_lnd::lnrpc::GetInfoRequest;

Expand Down Expand Up @@ -117,6 +120,10 @@ async fn main() -> Result<(), ()> {

info!("Starting lndk's grpc server at address {grpc_host}:{grpc_port}");

// Set up signal handlers for SIGTERM and SIGINT
let mut sigterm = signal(SignalKind::terminate()).expect("failed to set up SIGTERM handler");
let mut sigint = signal(SignalKind::interrupt()).expect("failed to set up SIGINT handler");

Check warning on line 126 in src/main.rs

View check run for this annotation

Codecov / codecov/patch

src/main.rs#L123-L126

Added lines #L123 - L126 were not covered by tests
select! {
_ = messenger.run(args, Arc::clone(&handler)) => {
info!("Onion messenger completed");
Expand All @@ -127,6 +134,12 @@ async fn main() -> Result<(), ()> {
Err(e) => error!("Error running API: {}", e),
};
},
_ = sigterm.recv() => {
info!("Received SIGTERM, shutting down");
},
_ = sigint.recv() => {
info!("Received SIGINT, shutting down");
},

Check warning on line 142 in src/main.rs

View check run for this annotation

Codecov / codecov/patch

src/main.rs#L137-L142

Added lines #L137 - L142 were not covered by tests
}

Ok(())
Expand Down

0 comments on commit ef878ee

Please sign in to comment.