diff options
author | Alex Auvolat <alex@adnab.me> | 2021-12-08 17:50:40 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2021-12-08 17:50:40 +0100 |
commit | 3bdb417bfb87d7ef3381be2d56346a7995c54dde (patch) | |
tree | a1c1f503f9010c6af37e2098e9125b39219274da /src/main.rs | |
parent | 0e6e60d35a20d3c5e691f01e7f9372a390c18dea (diff) | |
download | tricot-3bdb417bfb87d7ef3381be2d56346a7995c54dde.tar.gz tricot-3bdb417bfb87d7ef3381be2d56346a7995c54dde.zip |
Exit more agressively on certain errors
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs index d495fb2..987c3ec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ #[macro_use] extern crate anyhow; +use futures::TryFutureExt; use std::net::SocketAddr; use structopt::StructOpt; @@ -65,6 +66,12 @@ async fn main() { } pretty_env_logger::init(); + // Abort on panic (same behavior as in Go) + std::panic::set_hook(Box::new(|panic_info| { + error!("{}", panic_info.to_string()); + std::process::abort(); + })); + let opt = Opt::from_args(); info!("Starting Tricot"); @@ -77,14 +84,17 @@ async fn main() { rx_proxy_config.clone(), opt.letsencrypt_email.clone(), ); - tokio::spawn(cert_store.clone().watch_proxy_config()); - - tokio::spawn(http::serve_http(opt.http_bind_addr, consul.clone())); - tokio::spawn(https::serve_https( - opt.https_bind_addr, - cert_store.clone(), - rx_proxy_config.clone(), - )); + tokio::spawn(cert_store.clone().watch_proxy_config().map_err(exit_on_err)); + + tokio::spawn(http::serve_http(opt.http_bind_addr, consul.clone()).map_err(exit_on_err)); + tokio::spawn( + https::serve_https( + opt.https_bind_addr, + cert_store.clone(), + rx_proxy_config.clone(), + ) + .map_err(exit_on_err), + ); while rx_proxy_config.changed().await.is_ok() { info!("Proxy config:"); @@ -93,3 +103,8 @@ async fn main() { } } } + +fn exit_on_err(e: anyhow::Error) -> () { + error!("{}", e); + std::process::exit(1); +} |