ptth/crates/ptth_relay/src/main.rs

53 lines
1.0 KiB
Rust
Raw Normal View History

2020-11-29 20:22:40 +00:00
#![warn (clippy::pedantic)]
2020-11-02 03:34:50 +00:00
use std::{
2020-11-29 16:58:56 +00:00
convert::TryFrom,
2020-11-02 03:34:50 +00:00
error::Error,
2020-11-25 03:09:21 +00:00
path::PathBuf,
2020-11-02 18:39:19 +00:00
sync::Arc,
2020-11-02 03:34:50 +00:00
};
use tracing::{info};
use tracing_subscriber::{
fmt,
fmt::format::FmtSpan,
EnvFilter,
};
2020-11-27 00:20:18 +00:00
use ptth_relay::{
Config,
git_version::read_git_version,
RelayState,
2020-11-27 00:20:18 +00:00
run_relay,
};
2020-11-02 18:39:19 +00:00
#[tokio::main]
async fn main () -> Result <(), Box <dyn Error>> {
fmt ()
.with_env_filter (EnvFilter::from_default_env ())
.with_span_events (FmtSpan::FULL)
.init ()
;
2020-11-25 03:09:21 +00:00
let config_path = PathBuf::from ("config/ptth_relay.toml");
let config = Config::from_file (&config_path).await?;
2020-11-02 03:34:50 +00:00
match read_git_version ().await {
Some (x) => info! ("ptth_relay Git version: {:?}", x),
None => info! ("ptth_relay not built from Git"),
}
2020-11-27 00:03:11 +00:00
let (shutdown_rx, forced_shutdown) = ptth_core::graceful_shutdown::init_with_force ();
2020-11-07 02:29:45 +00:00
forced_shutdown.wrap_server (
2020-11-27 00:20:18 +00:00
run_relay (
2020-11-29 16:58:56 +00:00
Arc::new (RelayState::try_from (config)?),
Arc::new (ptth_relay::load_templates (&PathBuf::new ())?),
2020-11-25 03:09:21 +00:00
shutdown_rx,
Some (config_path)
2020-11-07 02:29:45 +00:00
)
).await??;
Ok (())
}