ci / rust (push) Successful in 1m0s
Closes NAP-221. Adds the `maestro-registry` bin so the registry can be spawned as a child process (required by the NAP-217 E2E harness) and run as a long-lived service. - New `crates/maestro-registry/src/main.rs` with a `#[tokio::main]` entry point: loads config via `ensure_token` (override path via `MAESTRO_REGISTRY_CONFIG`), binds the configured `bind_addr`, serves the production router, and shuts down cleanly on Ctrl-C. Mirrors the `maestrod` wiring (EnvFilter tracing, ExitCode reporting). - `[lib]` + `[[bin]]` sections in `crates/maestro-registry/Cargo.toml` so the crate exposes both surfaces (same pattern as `maestro-daemon`). - `RegistryConfig` gains a `bind_addr: SocketAddr` field with `serde(default)` to default to `127.0.0.1:8080` per spec §Registry. Existing TOML files without the field still load. - `default_config_path` re-exported from the crate root for the bin. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
50 lines
1.5 KiB
Rust
50 lines
1.5 KiB
Rust
//! `maestro-registry` — the Maestro always-on registry binary.
|
|
|
|
use std::error::Error;
|
|
use std::path::PathBuf;
|
|
use std::process::ExitCode;
|
|
|
|
use maestro_registry::{default_config_path, ensure_token, router, Registry};
|
|
use tokio::net::TcpListener;
|
|
use tracing_subscriber::EnvFilter;
|
|
|
|
#[tokio::main]
|
|
async fn main() -> ExitCode {
|
|
let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));
|
|
tracing_subscriber::fmt().with_env_filter(filter).init();
|
|
|
|
match run().await {
|
|
Ok(()) => ExitCode::SUCCESS,
|
|
Err(e) => {
|
|
tracing::error!(error = %e, "maestro-registry failed");
|
|
ExitCode::FAILURE
|
|
}
|
|
}
|
|
}
|
|
|
|
async fn run() -> Result<(), Box<dyn Error>> {
|
|
let config_path: PathBuf = match std::env::var_os("MAESTRO_REGISTRY_CONFIG") {
|
|
Some(p) => PathBuf::from(p),
|
|
None => default_config_path()?,
|
|
};
|
|
let config = ensure_token(&config_path)?;
|
|
tracing::info!(config = %config_path.display(), bind = %config.bind_addr, "loaded config");
|
|
|
|
let listener = TcpListener::bind(config.bind_addr).await?;
|
|
let bound = listener.local_addr()?;
|
|
tracing::info!(addr = %bound, "registry listening");
|
|
|
|
let registry = Registry::new();
|
|
let app = router(registry, config.token);
|
|
|
|
let shutdown = async {
|
|
let _ = tokio::signal::ctrl_c().await;
|
|
tracing::info!("ctrl-c received — shutting down");
|
|
};
|
|
|
|
axum::serve(listener, app)
|
|
.with_graceful_shutdown(shutdown)
|
|
.await?;
|
|
Ok(())
|
|
}
|