From 73fc14dec0d0b8e9f22aa473ac6d20e599773a17 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 20 Jan 2023 15:34:45 +0100 Subject: [PATCH] Entrypoint: re-try database connection on error for <=5m --- .../db-init/application/clicommands/DbCommand.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/entrypoint/db-init/application/clicommands/DbCommand.php b/entrypoint/db-init/application/clicommands/DbCommand.php index e8967f4..0d823e1 100644 --- a/entrypoint/db-init/application/clicommands/DbCommand.php +++ b/entrypoint/db-init/application/clicommands/DbCommand.php @@ -11,6 +11,7 @@ use Icinga\Data\Filter\Filter; use Icinga\Data\ResourceFactory; use Icinga\Module\Setup\Utils\DbTool; use Icinga\Util\Json; +use PDOException; class DbCommand extends Command { @@ -94,6 +95,20 @@ class DbCommand extends Command } } + for ($i = 0; $i < 100; ++$i) { + try { + (new DbTool($config))->checkConnectivity(); + break; + } catch (PDOException $e) { + fprintf( + STDERR, "[%s] [docker_entrypoint:error] [pid %d] DOCKERE: Can't connect to database: %s\n", + date('D M j H:i:s.u Y'), getmypid(), $e->getMessage() + ); + + sleep(3); + } + } + $db = new DbTool($config); $db->connectToDb(); $db->dbType = $type;