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;