mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 09:49:28 +02:00
Adding Wait for DB check
This commit is contained in:
parent
c40f48398e
commit
4c232fca36
3 changed files with 39 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
31
deploy/wait-for-db.php
Normal 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);
|
Loading…
Add table
Add a link
Reference in a new issue