objectstore_server/
healthcheck.rs

1//! CLI healthcheck subcommand implementation.
2
3use anyhow::Result;
4
5use crate::config::Config;
6
7/// Sends an HTTP GET to the `/health` endpoint and exits with an error if the response is not 2xx.
8///
9/// Used as the implementation of the `healthcheck` CLI subcommand, suitable for use in Docker
10/// `HEALTHCHECK` instructions.
11pub async fn healthcheck(config: Config) -> Result<()> {
12    let client = reqwest::Client::new();
13    let url = format!("http://{}/health", config.http_addr);
14
15    tracing::debug!("sending healthcheck request to {}", url);
16    let response = client.get(&url).send().await?;
17    if !response.status().is_success() {
18        anyhow::bail!("Bad Status: {}", response.status());
19    }
20
21    tracing::info!("OK");
22    Ok(())
23}