aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs31
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);
+}