From 7360d998f34b25662f781527820641b241c885ad Mon Sep 17 00:00:00 2001 From: Alexander Piskun Date: Thu, 31 Oct 2024 18:16:46 +0200 Subject: [PATCH] check healthcheck and heartbeat after ExApp container start Signed-off-by: bigcat88 --- lib/Service/AppAPIService.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/Service/AppAPIService.php b/lib/Service/AppAPIService.php index 5618c735..de5deb2a 100644 --- a/lib/Service/AppAPIService.php +++ b/lib/Service/AppAPIService.php @@ -560,7 +560,23 @@ public function enableExApp(ExApp $exApp): bool { if ($exApp->getAcceptsDeployId() === $this->dockerActions->getAcceptsDeployId()) { $daemonConfig = $this->daemonConfigService->getDaemonConfigByName($exApp->getDaemonConfigName()); $this->dockerActions->initGuzzleClient($daemonConfig); - $this->dockerActions->startContainer($this->dockerActions->buildDockerUrl($daemonConfig), $this->dockerActions->buildExAppContainerName($exApp->getAppid())); + $containerName = $this->dockerActions->buildExAppContainerName($exApp->getAppid()); + $this->dockerActions->startContainer($this->dockerActions->buildDockerUrl($daemonConfig), $containerName); + if (!$this->dockerActions->waitTillContainerStart($containerName, $daemonConfig)) { + $this->logger->error(sprintf('ExApp %s container startup failed.', $exApp->getAppid())); + return false; + } + if (!$this->dockerActions->healthcheckContainer($containerName, $daemonConfig, true)) { + $this->logger->error(sprintf('ExApp %s container healthcheck failed.', $exApp->getAppid())); + return false; + } + } + + $auth = []; + $exAppRootUrl = $this->getExAppUrl($exApp, $exApp->getPort(), $auth); + if (!$this->heartbeatExApp($exAppRootUrl, $auth, $exApp->getAppid())) { + $this->logger->error(sprintf('ExApp %s heartbeat failed.', $exApp->getAppid())); + return false; } $exAppEnabled = $this->requestToExApp($exApp, '/enabled?enabled=1', null, 'PUT', options: ['timeout' => 60]);