Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions glpi/files/opt/glpi/cron-worker.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash
set -e -u -o pipefail

# Wait for database to be ready before starting cron tasks
/opt/glpi/entrypoint/wait-for-db.sh cron-worker

# Infinite loop to run GLPI cron tasks every minute
while true; do
php /var/www/glpi/front/cron.php || echo "Cron task failed"
Expand Down
1 change: 1 addition & 0 deletions glpi/files/opt/glpi/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set -e -u -o pipefail

/opt/glpi/entrypoint/init-volumes-directories.sh
/opt/glpi/entrypoint/forward-logs.sh
/opt/glpi/entrypoint/wait-for-db.sh entrypoint
/opt/glpi/entrypoint/install.sh

exec "$@"
9 changes: 9 additions & 0 deletions glpi/files/opt/glpi/entrypoint/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ GLPI_Installed() {
return 1
}

# Skipping auto stuff, database configuration is not fully provided
if [ -z "${GLPI_DB_HOST:-}" ] || [ -z "${GLPI_DB_PORT:-}" ] || [ -z "${GLPI_DB_NAME:-}" ] || [ -z "${GLPI_DB_USER:-}" ] || [ -z "${GLPI_DB_PASSWORD:-}" ]; then
if ! $GLPI_SKIP_AUTOINSTALL || ! $GLPI_SKIP_AUTOUPDATE; then
echo "Database configuration incomplete, forcing GLPI_SKIP_AUTOINSTALL and GLPI_SKIP_AUTOUPDATE to true."
fi
GLPI_SKIP_AUTOINSTALL=true
GLPI_SKIP_AUTOUPDATE=true
fi

if ! GLPI_Installed; then
if ! $GLPI_SKIP_AUTOINSTALL; then
echo "GLPI is not installed. but auto-install is enabled. Starting installation."
Expand Down
35 changes: 35 additions & 0 deletions glpi/files/opt/glpi/entrypoint/wait-for-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
set -e -u -o pipefail

# Wait for database to be ready before proceeding
# Uses PHP mysqli to check database connectivity
# Usage: wait-for-db.sh [caller_name]

caller="${1:-unknown}"

# Skip if database configuration is not fully provided
if [ -z "${GLPI_DB_HOST:-}" ] || [ -z "${GLPI_DB_PORT:-}" ] || [ -z "${GLPI_DB_NAME:-}" ] || [ -z "${GLPI_DB_USER:-}" ] || [ -z "${GLPI_DB_PASSWORD:-}" ]; then
echo "[$caller] Database ENV configuration incomplete, skipping database state checks."
exit 0
fi

echo "[$caller] Waiting for database to be ready..."
attempts_left=120

until [ $attempts_left -eq 0 ]; do
# Try a simple database connection check using PHP mysqli
if php -r "
\$conn = @new mysqli('$GLPI_DB_HOST', '$GLPI_DB_USER', '$GLPI_DB_PASSWORD', '', (int) '$GLPI_DB_PORT');
exit(\$conn->connect_error ? 1 : 0);
" 2>/dev/null; then
echo "[$caller] The database is now ready and reachable."
exit 0
fi

sleep 1
attempts_left=$((attempts_left - 1))
echo "[$caller] Still waiting for database to be ready... $attempts_left attempts left."
done

echo "[$caller] The database is not up or not reachable."
exit 1