//! `maestro-web` binary entry point. See `lib.rs` for the architecture. use std::error::Error; use std::path::PathBuf; use std::process::ExitCode; use clap::Parser; use maestro_web::config::{default_config_path, EnvOverrides}; use maestro_web::{load_config, router}; use tokio::net::TcpListener; use tracing_subscriber::EnvFilter; #[derive(Debug, Parser)] #[command( name = "maestro-web", version, about = "Serves the Maestro web UI and reverse-proxies to a co-located maestrod" )] struct Cli { /// Override the unified Maestro config-file path. #[arg(long, env = "MAESTRO_CONFIG")] config: Option, } #[tokio::main] async fn main() -> ExitCode { let cli = Cli::parse(); let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")); tracing_subscriber::fmt().with_env_filter(filter).init(); match run(cli.config).await { Ok(()) => ExitCode::SUCCESS, Err(e) => { tracing::error!(error = %e, "maestro-web failed"); eprintln!("maestro-web: {e}"); ExitCode::FAILURE } } } async fn run(config_override: Option) -> Result<(), Box> { let path = match config_override { Some(p) => p, None => default_config_path()?, }; let cfg = load_config(&path, EnvOverrides::from_env())?; tracing::info!( bind = %cfg.bind_addr, daemon = %cfg.daemon_url, "loaded config", ); let router = router(&cfg)?; let listener = TcpListener::bind(cfg.bind_addr).await?; tracing::info!(addr = %listener.local_addr()?, "serving"); axum::serve(listener, router) .with_graceful_shutdown(async { let _ = tokio::signal::ctrl_c().await; tracing::info!("ctrl-c received — shutting down"); }) .await?; Ok(()) }