diff --git a/slingshot/src/main.rs b/slingshot/src/main.rs index ae5fdbb..b2cc768 100644 --- a/slingshot/src/main.rs +++ b/slingshot/src/main.rs @@ -49,6 +49,12 @@ struct Args { /// an web address to send healtcheck pings to every ~51s or so #[arg(long)] healthcheck: Option, + /// slingshot server's listen address + #[arg(long, default_value = "0.0.0.0:8080")] + bind: std::net::SocketAddr, + /// metrics server's listen address + #[arg(long, default_value = "0.0.0.0:8765")] + bind_metrics: std::net::SocketAddr, } #[tokio::main] @@ -62,10 +68,10 @@ async fn main() -> Result<(), String> { let args = Args::parse(); - if let Err(e) = install_metrics_server() { + if let Err(e) = install_metrics_server(args.bind_metrics) { log::error!("failed to install metrics server: {e:?}"); } else { - log::info!("metrics listening at http://0.0.0.0:8765"); + log::info!("metrics listening at http://{}", args.bind_metrics); } std::fs::create_dir_all(&args.cache_dir).map_err(|e| { @@ -104,6 +110,7 @@ async fn main() -> Result<(), String> { let server_shutdown = shutdown.clone(); let server_cache_handle = cache.clone(); + let bind = args.bind; tasks.spawn(async move { serve( server_cache_handle, @@ -113,6 +120,7 @@ async fn main() -> Result<(), String> { args.acme_contact, args.certs, server_shutdown, + bind, ) .await?; Ok(()) @@ -172,23 +180,18 @@ async fn main() -> Result<(), String> { Ok(()) } -fn install_metrics_server() -> Result<(), metrics_exporter_prometheus::BuildError> { +fn install_metrics_server(bind_metrics: std::net::SocketAddr) -> Result<(), metrics_exporter_prometheus::BuildError> { log::info!("installing metrics server..."); - let host = [0, 0, 0, 0]; - let port = 8765; PrometheusBuilder::new() .set_quantiles(&[0.5, 0.9, 0.99, 1.0])? .set_bucket_duration(std::time::Duration::from_secs(300))? .set_bucket_count(std::num::NonZero::new(12).unwrap()) // count * duration = 60 mins. stuff doesn't happen that fast here. .set_enable_unit_suffix(false) // this seemed buggy for constellation (sometimes wouldn't engage) - .with_http_listener((host, port)) + .with_http_listener(bind_metrics) .install()?; log::info!( - "metrics server installed! listening on http://{}.{}.{}.{}:{port}", - host[0], - host[1], - host[2], - host[3] + "metrics server installed! listening on http://{}", + bind_metrics ); Ok(()) } diff --git a/slingshot/src/server.rs b/slingshot/src/server.rs index 7985dd2..30fce0a 100644 --- a/slingshot/src/server.rs +++ b/slingshot/src/server.rs @@ -695,6 +695,7 @@ pub async fn serve( acme_contact: Option, certs: Option, shutdown: CancellationToken, + bind: std::net::SocketAddr, ) -> Result<(), ServerError> { let repo = Arc::new(repo); let api_service = OpenApiService::new( @@ -752,7 +753,7 @@ pub async fn serve( ) .await } else { - run(TcpListener::bind("127.0.0.1:3000"), app, shutdown).await + run(TcpListener::bind(bind.to_string()), app, shutdown).await } } diff --git a/spacedust/src/main.rs b/spacedust/src/main.rs index 54db30e..df99eff 100644 --- a/spacedust/src/main.rs +++ b/spacedust/src/main.rs @@ -23,6 +23,12 @@ struct Args { /// reduces CPU at the expense of more ingress bandwidth #[arg(long, action)] jetstream_no_zstd: bool, + /// spacedust server's listen address + #[arg(long, default_value = "0.0.0.0:9998")] + bind: std::net::SocketAddr, + /// metrics server's listen address + #[arg(long, default_value = "0.0.0.0:8765")] + bind_metrics: std::net::SocketAddr, } #[tokio::main] @@ -60,15 +66,16 @@ async fn main() -> Result<(), String> { let args = Args::parse(); - if let Err(e) = install_metrics_server() { + if let Err(e) = install_metrics_server(args.bind_metrics) { log::error!("failed to install metrics server: {e:?}"); }; let mut tasks: tokio::task::JoinSet> = tokio::task::JoinSet::new(); let server_shutdown = shutdown.clone(); + let bind = args.bind; tasks.spawn(async move { - server::serve(b, d, server_shutdown).await?; + server::serve(b, d, server_shutdown, bind).await?; Ok(()) }); @@ -122,23 +129,18 @@ async fn main() -> Result<(), String> { Ok(()) } -fn install_metrics_server() -> Result<(), metrics_exporter_prometheus::BuildError> { +fn install_metrics_server(bind_metrics: std::net::SocketAddr) -> Result<(), metrics_exporter_prometheus::BuildError> { log::info!("installing metrics server..."); - let host = [0, 0, 0, 0]; - let port = 8765; PrometheusBuilder::new() .set_quantiles(&[0.5, 0.9, 0.99, 1.0])? .set_bucket_duration(std::time::Duration::from_secs(300))? .set_bucket_count(std::num::NonZero::new(12).unwrap()) // count * duration = 60 mins. stuff doesn't happen that fast here. .set_enable_unit_suffix(false) // this seemed buggy for constellation (sometimes wouldn't engage) - .with_http_listener((host, port)) + .with_http_listener(bind_metrics) .install()?; log::info!( - "metrics server installed! listening on http://{}.{}.{}.{}:{port}", - host[0], - host[1], - host[2], - host[3] + "metrics server installed! listening on http://{}", + bind_metrics ); Ok(()) } diff --git a/spacedust/src/server.rs b/spacedust/src/server.rs index 9d3dcf6..89b6e65 100644 --- a/spacedust/src/server.rs +++ b/spacedust/src/server.rs @@ -29,6 +29,7 @@ pub async fn serve( b: broadcast::Sender>, d: broadcast::Sender>, shutdown: CancellationToken, + bind: std::net::SocketAddr, ) -> Result<(), ServerError> { let config_logging = ConfigLogging::StderrTerminal { level: ConfigLoggingLevel::Info, @@ -72,7 +73,7 @@ pub async fn serve( let server = ServerBuilder::new(api, ctx, log) .config(ConfigDropshot { - bind_address: "0.0.0.0:9998".parse().unwrap(), + bind_address: bind, ..Default::default() }) .start()?; diff --git a/ufos/src/main.rs b/ufos/src/main.rs index 949db21..76dd580 100644 --- a/ufos/src/main.rs +++ b/ufos/src/main.rs @@ -55,6 +55,12 @@ struct Args { /// DEBUG: interpret jetstream as a file fixture #[arg(long, action)] jetstream_fixture: bool, + /// ufos server's listen address + #[arg(long, default_value = "0.0.0.0:9990")] + bind: std::net::SocketAddr, + /// metrics server's listen address + #[arg(long, default_value = "0.0.0.0:8765")] + bind_metrics: std::net::SocketAddr, } #[tokio::main] @@ -84,7 +90,7 @@ async fn go( let mut consumer_tasks: JoinSet> = JoinSet::new(); println!("starting server with storage..."); - let serving = server::serve(read_store.clone()); + let serving = server::serve(read_store.clone(), args.bind); whatever_tasks.spawn(async move { serving.await.map_err(|e| { log::warn!("server ended: {e}"); @@ -137,7 +143,7 @@ async fn go( Ok(()) }); - install_metrics_server()?; + install_metrics_server(args.bind_metrics)?; for (i, t) in consumer_tasks.join_all().await.iter().enumerate() { log::warn!("task {i} done: {t:?}"); @@ -151,23 +157,18 @@ async fn go( Ok(()) } -fn install_metrics_server() -> anyhow::Result<()> { +fn install_metrics_server(bind_metrics: std::net::SocketAddr) -> anyhow::Result<()> { log::info!("installing metrics server..."); - let host = [0, 0, 0, 0]; - let port = 8765; PrometheusBuilder::new() .set_quantiles(&[0.5, 0.9, 0.99, 1.0])? .set_bucket_duration(Duration::from_secs(60))? .set_bucket_count(std::num::NonZero::new(10).unwrap()) // count * duration = 10 mins. stuff doesn't happen that fast here. .set_enable_unit_suffix(false) // this seemed buggy for constellation (sometimes wouldn't engage) - .with_http_listener((host, port)) + .with_http_listener(bind_metrics) .install()?; log::info!( - "metrics server installed! listening on http://{}.{}.{}.{}:{port}", - host[0], - host[1], - host[2], - host[3] + "metrics server installed! listening on http://{}", + bind_metrics ); Ok(()) } diff --git a/ufos/src/server/mod.rs b/ufos/src/server/mod.rs index 2a054e7..1626ee1 100644 --- a/ufos/src/server/mod.rs +++ b/ufos/src/server/mod.rs @@ -716,7 +716,7 @@ async fn search_collections( .await } -pub async fn serve(storage: impl StoreReader + 'static) -> Result<(), String> { +pub async fn serve(storage: impl StoreReader + 'static, bind: std::net::SocketAddr) -> Result<(), String> { describe_metrics(); let log = ConfigLogging::StderrTerminal { level: ConfigLoggingLevel::Warn, @@ -758,7 +758,7 @@ pub async fn serve(storage: impl StoreReader + 'static) -> Result<(), String> { ServerBuilder::new(api, context, log) .config(ConfigDropshot { - bind_address: "0.0.0.0:9999".parse().unwrap(), + bind_address: bind, ..Default::default() }) .start()