From ab5347d907e696c024fe17bf75cd92e5483e2f14 Mon Sep 17 00:00:00 2001 From: "Yuri (solarw) Turchenkov" Date: Tue, 18 Jun 2024 15:47:31 +0300 Subject: [PATCH] pause all service on startup --- operate/cli.py | 17 +++++++++++++++++ operate/services/service.py | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/operate/cli.py b/operate/cli.py index 821fa88ac..646435a33 100644 --- a/operate/cli.py +++ b/operate/cli.py @@ -179,6 +179,23 @@ def cancel_funding_job(service: str) -> None: if not status: logger.info(f"Funding job cancellation for {service} failed") + def pause_all_services_on_startup(): + logger.info(f"stopping services on startup") + services = [i["hash"] for i in operate.service_manager().json] + + for service in services: + if not operate.service_manager().exists(service=service): + continue + logger.info(f"stopping service {service}") + deployment = operate.service_manager().create_or_load(service).deployment + deployment.stop(force=True) + logger.info(f"Cancelling funding job for {service}") + cancel_funding_job(service=service) + logger.info(f"stopping services on startup: done") + + # on backend app started we assume there are now started agents, so we force to pause all + pause_all_services_on_startup() + app = FastAPI() app.add_middleware( diff --git a/operate/services/service.py b/operate/services/service.py index 1f03d93ab..2f05c6d9e 100644 --- a/operate/services/service.py +++ b/operate/services/service.py @@ -822,9 +822,9 @@ def start(self, use_docker: bool = False) -> None: self.status = DeploymentStatus.DEPLOYED self.store() - def stop(self, use_docker: bool = False) -> None: + def stop(self, use_docker: bool = False, force: bool=False) -> None: """Stop the deployment.""" - if self.status != DeploymentStatus.DEPLOYED: + if self.status != DeploymentStatus.DEPLOYED and not force: return self.status = DeploymentStatus.STOPPING