1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 01:39:24 +02:00

Adding Wait for DB check

This commit is contained in:
Thoralf Rickert-Wendt 2022-02-04 16:24:00 +01:00
parent c40f48398e
commit 4c232fca36
3 changed files with 39 additions and 0 deletions

View file

@ -68,6 +68,7 @@ RUN apt install -y --no-install-recommends \
COPY deploy/apache/avideo.conf /etc/apache2/sites-enabled/000-default.conf
COPY deploy/apache/phpmyadmin.conf /etc/apache2/conf-available/phpmyadmin.conf
COPY deploy/docker-entrypoint /usr/local/bin/docker-entrypoint
COPY deploy/wait-for-db.php /usr/local/bin/wait-for-db.php
COPY admin /var/www/html/AVideo/admin
COPY feed /var/www/html/AVideo/feed

View file

@ -55,6 +55,13 @@ if [ "_${ENABLE_PHPMYADMIN}_" = "_yes_" ]; then
a2enmod proxy_http
fi
echo "Waiting for database ${DB_MYSQL_HOST} to be up and running"
php /usr/local/bin/wait-for-db.php
if [ $? -ne 0 ]; then
echo "Stopping container"
exit 1
fi
if [ -f /var/www/html/AVideo/videos/configuration.php ]; then
echo "Using existing configuration..."
else

31
deploy/wait-for-db.php Normal file
View file

@ -0,0 +1,31 @@
<?php
$counter = 0;
$sleep = 5;
$timeout = 60;
$connected = false;
$db_host = getenv("DB_MYSQL_HOST");
$db_port = getenv("DB_MYSQL_PORT");
$db_name = getenv("DB_MYSQL_NAME");
$db_user = getenv("DB_MYSQL_USER");
$db_pass = getenv("DB_MYSQL_PASSWORD");
while (!$connected) {
echo "Checking database connection....";
$mysqli = @new mysqli($db_host, $db_user, $db_pass, $db_name, $db_port);
if ($mysqli !== false) {
echo "OK\n";
$connected = true;
} else {
$counter ++;
echo "Failed (attempt ".$counter.")\n";
if ($counter*$sleep > $timeout) {
echo "Giving up...";
exit(1);
}
sleep($sleep);
}
}
exit(0);