objectstore_server/
cli.rs1use std::path::PathBuf;
2
3use anyhow::Result;
4use argh::FromArgs;
5
6use crate::config::Config;
7use crate::{healthcheck, http, observability};
8
9#[derive(Debug, FromArgs)]
11struct Args {
12 #[argh(option, short = 'c')]
14 pub config: Option<PathBuf>,
15
16 #[argh(subcommand)]
17 pub command: Command,
18}
19
20#[derive(Debug, FromArgs)]
21#[argh(subcommand)]
22enum Command {
23 Run(RunCommand),
24 Healthcheck(HealthcheckCommand),
25}
26
27#[derive(Debug, FromArgs)]
29#[argh(subcommand, name = "run")]
30struct RunCommand {}
31
32#[derive(Debug, FromArgs)]
37#[argh(subcommand, name = "healthcheck")]
38struct HealthcheckCommand {}
39
40pub fn execute() -> Result<()> {
42 let args: Args = argh::from_env();
43 let config = Config::load(args.config.as_deref())?;
44
45 rustls::crypto::ring::default_provider()
47 .install_default()
48 .map_err(|_| anyhow::anyhow!("Failed to install rustls crypto provider"))?;
49
50 let _sentry_guard = observability::init_sentry(&config);
52
53 let runtime = tokio::runtime::Builder::new_multi_thread()
54 .thread_name("main-rt")
55 .enable_all()
56 .worker_threads(config.runtime.worker_threads)
57 .build()?;
58 let _runtime_guard = runtime.enter();
59
60 observability::init_tracing(&config);
61 tracing::debug!(?config);
62
63 let metrics_guard = observability::init_metrics(&config)?;
64
65 let result = runtime.block_on(async move {
66 match args.command {
67 Command::Run(RunCommand {}) => http::server(config).await,
68 Command::Healthcheck(HealthcheckCommand {}) => healthcheck::healthcheck(config).await,
69 }
70 });
71
72 runtime.block_on(async {
74 if let Some(metrics_guard) = metrics_guard {
75 metrics_guard.flush(None).await.ok();
76 }
77 });
78
79 result
80}