diff --git a/crates/cli/src/docker_init.rs b/crates/cli/src/docker_init.rs index e3ae71ef..1969efb9 100644 --- a/crates/cli/src/docker_init.rs +++ b/crates/cli/src/docker_init.rs @@ -15,6 +15,7 @@ use cb_common::{ SIGNER_DIR_SECRETS_ENV, SIGNER_KEYS_ENV, SIGNER_MODULE_NAME, SIGNER_PORT_ENV, SIGNER_URL_ENV, }, + pbs::{BUILDER_API_PATH, GET_STATUS_PATH}, signer::{ProxyStore, SignerLoader}, types::ModuleId, utils::random_jwt, @@ -295,6 +296,17 @@ pub async fn handle_docker_init(config_path: String, output_dir: String) -> Resu networks: pbs_networs, volumes: pbs_volumes, environment: Environment::KvPair(pbs_envs), + healthcheck: Some(Healthcheck { + test: Some(HealthcheckTest::Single(format!( + "curl -f http://localhost:{}{}{}", + cb_config.pbs.pbs_config.port, BUILDER_API_PATH, GET_STATUS_PATH + ))), + interval: Some("30s".into()), + timeout: Some("5s".into()), + retries: 3, + start_period: Some("5s".into()), + disable: false, + }), ..Service::default() }; @@ -413,10 +425,10 @@ pub async fn handle_docker_init(config_path: String, output_dir: String) -> Resu test: Some(HealthcheckTest::Single(format!( "curl -f http://localhost:{signer_port}/status" ))), - interval: Some("5s".into()), + interval: Some("30s".into()), timeout: Some("5s".into()), - retries: 5, - start_period: Some("0s".into()), + retries: 3, + start_period: Some("5s".into()), disable: false, }), ..Service::default() diff --git a/crates/pbs/src/service.rs b/crates/pbs/src/service.rs index 0f88becd..2533573b 100644 --- a/crates/pbs/src/service.rs +++ b/crates/pbs/src/service.rs @@ -1,9 +1,15 @@ -use cb_common::constants::COMMIT_BOOST_VERSION; +use std::time::Duration; + +use cb_common::{ + constants::COMMIT_BOOST_VERSION, + pbs::{BUILDER_API_PATH, GET_STATUS_PATH}, +}; use cb_metrics::provider::MetricsProvider; -use eyre::{Context, Result}; +use eyre::{bail, Context, Result}; use prometheus::core::Collector; use tokio::net::TcpListener; use tracing::info; +use url::Url; use crate::{ api::BuilderApi, @@ -16,15 +22,30 @@ pub struct PbsService; impl PbsService { pub async fn run>(state: PbsState) -> Result<()> { - let address = state.config.endpoint; + let addr = state.config.endpoint; let events_subs = state.config.event_publisher.as_ref().map(|e| e.n_subscribers()).unwrap_or_default(); - info!(version = COMMIT_BOOST_VERSION, ?address, events_subs, chain =? state.config.chain, "starting PBS service"); + info!(version = COMMIT_BOOST_VERSION, ?addr, events_subs, chain =? state.config.chain, "starting PBS service"); let app = create_app_router::(state); - let listener = TcpListener::bind(address).await?; + let listener = TcpListener::bind(addr).await?; + + let task = + tokio::spawn( + async move { axum::serve(listener, app).await.wrap_err("PBS server exited") }, + ); + + // wait for the server to start + tokio::time::sleep(Duration::from_millis(250)).await; + let local_url = + Url::parse(&format!("http://{}{}{}", addr, BUILDER_API_PATH, GET_STATUS_PATH))?; + + let status = reqwest::get(local_url).await?; + if !status.status().is_success() { + bail!("PBS server failed to start. Are the relays properly configured?"); + } - axum::serve(listener, app).await.wrap_err("PBS server exited") + task.await? } pub fn register_metric(c: Box) { diff --git a/docker/pbs.Dockerfile b/docker/pbs.Dockerfile index 6171b07b..9d2a2fcf 100644 --- a/docker/pbs.Dockerfile +++ b/docker/pbs.Dockerfile @@ -22,6 +22,7 @@ RUN apt-get update && apt-get install -y \ ca-certificates \ libssl3 \ libssl-dev \ + curl \ && apt-get clean autoclean \ && rm -rf /var/lib/apt/lists/*