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 let args: Args = Docopt::new(USAGE)
41 .and_then(|d| d.deserialize())
42 .unwrap_or_else(|e| e.exit());
43 let settings = settings::Settings::with_env_and_config_file(&args.flag_config)?;
44 let host_port = format!("{}:{}", &settings.host, &settings.port);
45 logging::init_logging(
46 !settings.human_logs,
47 env!("CARGO_PKG_NAME"),
48 env!("CARGO_PKG_VERSION"),
49 )
50 .expect("Logging failed to initialize");
51 debug!("Starting up autoendpoint...");
52
53 let _sentry = sentry::init(sentry::ClientOptions {
54 release: sentry::release_name!(),
55 attach_stacktrace: true,
56 ..autopush_common::sentry::client_options()
57 });
58
59 let server = server::Server::with_settings(settings)
61 .await
62 .inspect_err(|e| error!("Server Start Error: {:?}", e))
63 .expect("Could not start server");
64 info!(
65 "Starting autoendpoint on port: {} ({})",
66 host_port,
67 logging::parallelism_banner()
68 );
69 server.await?;
70
71 info!("Shutting down autoendpoint");
73 logging::reset_logging();
74 Ok(())
75}