diff --git a/dstack/supervisor/src/web_api.rs b/dstack/supervisor/src/web_api.rs index 2521ee20b..a3529b0d5 100644 --- a/dstack/supervisor/src/web_api.rs +++ b/dstack/supervisor/src/web_api.rs @@ -6,7 +6,7 @@ use anyhow::{anyhow, Result}; use or_panic::ResultOrPanic; use rocket::figment::Figment; use rocket::serde::json::Json; -use rocket::{delete, get, post, routes, Build, Rocket, State}; +use rocket::{delete, get, post, routes, Build, Rocket, Shutdown, State}; use serde::{Deserialize, Serialize}; use tokio::signal; use tracing::info; @@ -81,8 +81,12 @@ fn clear(supervisor: &State) -> Json> { } #[post("/shutdown")] -async fn shutdown(supervisor: &State) -> Json> { - to_json(perform_shutdown(supervisor, false).await) +async fn shutdown(supervisor: &State, rocket_shutdown: Shutdown) -> Json> { + let result = supervisor.shutdown().await; + if result.is_ok() { + rocket_shutdown.notify(); + } + to_json(result) } async fn perform_shutdown(supervisor: &Supervisor, force: bool) -> Result<()> {