From 2537bc8cfcb77f868eaf8f25f8e79f479311d689 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Thu, 12 Mar 2026 16:35:37 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20healthcheck=20nunca=20retorna=20503=20?= =?UTF-8?q?=E2=80=94=20evita=20'no=20available=20server'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit health.php: - DB fallo → 'warning' (no 'unhealthy', no cierra tráfico Traefik) - Redis ya era warning desde commit anterior docker-compose.yml: - timeout: 5s → 10s (DB externa puede tardar más) - start_period: 40s → 60s (tiempo suficiente para that migrations corran) - fallback: si health.php falla, intenta / raíz antes de marcar unhealthy --- docker-compose.yml | 6 +++--- health.php | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index ff4f35e..455fd29 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -33,11 +33,11 @@ services: networks: - whatsapp-network healthcheck: - test: ["CMD", "curl", "-f", "http://localhost/health.php"] + test: ["CMD-SHELL", "curl -sf http://localhost/health.php || curl -sf http://localhost/ || exit 1"] interval: 30s - timeout: 5s + timeout: 10s retries: 3 - start_period: 40s + start_period: 60s logging: driver: "json-file" options: diff --git a/health.php b/health.php index ea8ff76..80fa823 100644 --- a/health.php +++ b/health.php @@ -30,15 +30,16 @@ try { $result = $db->query("SELECT 1")->fetch(); $health['checks']['database'] = [ - 'status' => $result ? 'ok' : 'error', + 'status' => $result ? 'ok' : 'warning', 'host' => DB_HOST ]; } catch (Exception $e) { + // DB caída = warning, no unhealthy — Traefik debe seguir ruteando + // (mejor mostrar error 500 en la app que "no available server") $health['checks']['database'] = [ - 'status' => 'error', + 'status' => 'warning', 'error' => $e->getMessage() ]; - $health['status'] = 'unhealthy'; } // 3. Check Redis