Merge pull request #89 from Icinga/db-conn-refused

Entrypoint: re-try database connection on error for <=5m
This commit is contained in:
Eric Lippmann 2023-01-20 16:27:12 +01:00 committed by GitHub
commit ce71661ede
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;