diff --git a/Cargo.lock b/Cargo.lock index 5a644ce8b5..336392acf0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1039,6 +1039,7 @@ dependencies = [ "tokio-stream", "tonic", "tonic-build", + "tonic-health", "tower-http", "tracing", "tracing-subscriber", @@ -4946,6 +4947,19 @@ dependencies = [ "syn 2.0.68", ] +[[package]] +name = "tonic-health" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cef6e24bc96871001a7e48e820ab240b3de2201e59b517cf52835df2f1d2350" +dependencies = [ + "async-stream", + "prost", + "tokio", + "tokio-stream", + "tonic", +] + [[package]] name = "tower" version = "0.4.13" diff --git a/Cargo.toml b/Cargo.toml index 6dc403ef54..0a3808be0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -102,6 +102,7 @@ x25519-dalek = { version = "2.0", features = ["static_secrets"] } # openapi utoipa = { version = "4", features = ["axum_extras"] } utoipa-swagger-ui = { version = "7", features = ["axum"] } +tonic-health = "0.11" [dev-dependencies] bytes = "1.6" diff --git a/src/grpc/mod.rs b/src/grpc/mod.rs index 784b40ce89..17e4e1b788 100644 --- a/src/grpc/mod.rs +++ b/src/grpc/mod.rs @@ -547,6 +547,12 @@ pub async fn run_grpc_server( GatewayServer::new(pool, gateway_state, wireguard_tx, mail_tx), JwtInterceptor::new(ClaimsType::Gateway), ); + + let (mut health_reporter, health_service) = tonic_health::server::health_reporter(); + health_reporter + .set_serving::>() + .await; + // Run gRPC server let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), server_config().grpc_port); debug!("Starting gRPC services"); @@ -559,6 +565,7 @@ pub async fn run_grpc_server( let router = builder .http2_keepalive_interval(Some(TEN_SECS)) .tcp_keepalive(Some(TEN_SECS)) + .add_service(health_service) .add_service(auth_service); #[cfg(feature = "wireguard")] let router = router.add_service(gateway_service);