diff --git a/templates/deployment.yaml b/templates/deployment.yaml index 70018d9..3875357 100644 --- a/templates/deployment.yaml +++ b/templates/deployment.yaml @@ -100,7 +100,15 @@ spec: max_attempts=30 attempt=0 while [ $attempt -lt $max_attempts ]; do - if /tmp/wp-cli.phar --path=/usr/src/wordpress db check 2>/dev/null; then + if php -r " + \$link = @mysqli_connect('${WORDPRESS_DB_HOST}', '${WORDPRESS_DB_USER}', '${WORDPRESS_DB_PASSWORD}', '${WORDPRESS_DB_NAME}'); + if (\$link) { + echo 'Connected'; + mysqli_close(\$link); + exit(0); + } + exit(1); + " 2>/dev/null; then echo "Database connection successful" break fi @@ -109,6 +117,14 @@ spec: sleep 2 done + if [ $attempt -eq $max_attempts ]; then + echo "ERROR: Database connection timeout" + echo "DB_HOST: ${WORDPRESS_DB_HOST}" + echo "DB_NAME: ${WORDPRESS_DB_NAME}" + echo "DB_USER: ${WORDPRESS_DB_USER}" + exit 1 + fi + echo "Checking if WordPress is already installed..." TABLES=$(/tmp/wp-cli.phar --path=/usr/src/wordpress db query "SHOW TABLES LIKE '${WORDPRESS_TABLE_PREFIX}options';" 2>/dev/null || echo "")