Skip to content

Commit fdd5d6d

Browse files
authored
chore(pbs): add status checks (#213)
1 parent 5749410 commit fdd5d6d

File tree

3 files changed

+43
-9
lines changed

3 files changed

+43
-9
lines changed

crates/cli/src/docker_init.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use cb_common::{
1515
SIGNER_DIR_SECRETS_ENV, SIGNER_KEYS_ENV, SIGNER_MODULE_NAME, SIGNER_PORT_ENV,
1616
SIGNER_URL_ENV,
1717
},
18+
pbs::{BUILDER_API_PATH, GET_STATUS_PATH},
1819
signer::{ProxyStore, SignerLoader},
1920
types::ModuleId,
2021
utils::random_jwt,
@@ -295,6 +296,17 @@ pub async fn handle_docker_init(config_path: String, output_dir: String) -> Resu
295296
networks: pbs_networs,
296297
volumes: pbs_volumes,
297298
environment: Environment::KvPair(pbs_envs),
299+
healthcheck: Some(Healthcheck {
300+
test: Some(HealthcheckTest::Single(format!(
301+
"curl -f http://localhost:{}{}{}",
302+
cb_config.pbs.pbs_config.port, BUILDER_API_PATH, GET_STATUS_PATH
303+
))),
304+
interval: Some("30s".into()),
305+
timeout: Some("5s".into()),
306+
retries: 3,
307+
start_period: Some("5s".into()),
308+
disable: false,
309+
}),
298310
..Service::default()
299311
};
300312

@@ -413,10 +425,10 @@ pub async fn handle_docker_init(config_path: String, output_dir: String) -> Resu
413425
test: Some(HealthcheckTest::Single(format!(
414426
"curl -f http://localhost:{signer_port}/status"
415427
))),
416-
interval: Some("5s".into()),
428+
interval: Some("30s".into()),
417429
timeout: Some("5s".into()),
418-
retries: 5,
419-
start_period: Some("0s".into()),
430+
retries: 3,
431+
start_period: Some("5s".into()),
420432
disable: false,
421433
}),
422434
..Service::default()

crates/pbs/src/service.rs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
use cb_common::constants::COMMIT_BOOST_VERSION;
1+
use std::time::Duration;
2+
3+
use cb_common::{
4+
constants::COMMIT_BOOST_VERSION,
5+
pbs::{BUILDER_API_PATH, GET_STATUS_PATH},
6+
};
27
use cb_metrics::provider::MetricsProvider;
3-
use eyre::{Context, Result};
8+
use eyre::{bail, Context, Result};
49
use prometheus::core::Collector;
510
use tokio::net::TcpListener;
611
use tracing::info;
12+
use url::Url;
713

814
use crate::{
915
api::BuilderApi,
@@ -16,15 +22,30 @@ pub struct PbsService;
1622

1723
impl PbsService {
1824
pub async fn run<S: BuilderApiState, A: BuilderApi<S>>(state: PbsState<S>) -> Result<()> {
19-
let address = state.config.endpoint;
25+
let addr = state.config.endpoint;
2026
let events_subs =
2127
state.config.event_publisher.as_ref().map(|e| e.n_subscribers()).unwrap_or_default();
22-
info!(version = COMMIT_BOOST_VERSION, ?address, events_subs, chain =? state.config.chain, "starting PBS service");
28+
info!(version = COMMIT_BOOST_VERSION, ?addr, events_subs, chain =? state.config.chain, "starting PBS service");
2329

2430
let app = create_app_router::<S, A>(state);
25-
let listener = TcpListener::bind(address).await?;
31+
let listener = TcpListener::bind(addr).await?;
32+
33+
let task =
34+
tokio::spawn(
35+
async move { axum::serve(listener, app).await.wrap_err("PBS server exited") },
36+
);
37+
38+
// wait for the server to start
39+
tokio::time::sleep(Duration::from_millis(250)).await;
40+
let local_url =
41+
Url::parse(&format!("http://{}{}{}", addr, BUILDER_API_PATH, GET_STATUS_PATH))?;
42+
43+
let status = reqwest::get(local_url).await?;
44+
if !status.status().is_success() {
45+
bail!("PBS server failed to start. Are the relays properly configured?");
46+
}
2647

27-
axum::serve(listener, app).await.wrap_err("PBS server exited")
48+
task.await?
2849
}
2950

3051
pub fn register_metric(c: Box<dyn Collector>) {

docker/pbs.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ RUN apt-get update && apt-get install -y \
2222
ca-certificates \
2323
libssl3 \
2424
libssl-dev \
25+
curl \
2526
&& apt-get clean autoclean \
2627
&& rm -rf /var/lib/apt/lists/*
2728

0 commit comments

Comments
 (0)