1#![warn(rust_2018_idioms)]
2
3#[global_allocator]
4static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
5
6#[macro_use]
7extern crate slog_scope;
8
9mod auth;
10mod error;
11mod extractors;
12mod headers;
13mod metrics;
14mod routers;
15mod routes;
16mod server;
17mod settings;
18
19use docopt::Docopt;
20use serde::Deserialize;
21use std::error::Error;
22
23use autopush_common::logging;
24
25const USAGE: &str = "
26Usage: autoendpoint [options]
27
28Options:
29 -h, --help Show this message
30 -c, --config=CONFIGFILE AutoEndpoint configuration file path.
31";
32
33#[derive(Debug, Deserialize)]
34struct Args {
35 flag_config: Option<String>,
36}
37
38#[actix_rt::main]
39async fn main() -> Result<(), Box<dyn Error>> {
40 autopush_common::tls::install_crypto_provider();
45 let args: Args = Docopt::new(USAGE)
46 .and_then(|d| d.deserialize())
47 .unwrap_or_else(|e| e.exit());
48 let settings = settings::Settings::with_env_and_config_file(&args.flag_config)?;
49 let host_port = format!("{}:{}", &settings.host, &settings.port);
50 logging::init_logging(
51 !settings.human_logs,
52 settings.log_chan_size,
53 env!("CARGO_PKG_NAME"),
54 env!("CARGO_PKG_VERSION"),
55 )
56 .expect("Logging failed to initialize");
57 debug!("Starting up autoendpoint...");
58
59 let _sentry = sentry::init(sentry::ClientOptions {
60 release: sentry::release_name!(),
61 attach_stacktrace: true,
62 ..autopush_common::sentry::client_options()
63 });
64
65 let server = server::Server::with_settings(settings)
67 .await
68 .inspect_err(|e| error!("Server Start Error: {:?}", e))
69 .expect("Could not start server");
70 info!(
71 "Starting autoendpoint on port: {} ({})",
72 host_port,
73 logging::parallelism_banner()
74 );
75 server.await?;
76
77 info!("Shutting down autoendpoint");
79 logging::reset_logging();
80 Ok(())
81}