73 lines
1.8 KiB
Bash
Executable File
73 lines
1.8 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
echo "==================================="
|
|
echo "Recticel Quality App - Starting"
|
|
echo "==================================="
|
|
|
|
# Wait for MariaDB to be ready
|
|
echo "Waiting for MariaDB to be ready..."
|
|
until python3 << END
|
|
import mariadb
|
|
import sys
|
|
import time
|
|
|
|
max_retries = 30
|
|
retry_count = 0
|
|
|
|
while retry_count < max_retries:
|
|
try:
|
|
conn = mariadb.connect(
|
|
user="${DB_USER}",
|
|
password="${DB_PASSWORD}",
|
|
host="${DB_HOST}",
|
|
port=int("${DB_PORT}"),
|
|
database="${DB_NAME}"
|
|
)
|
|
conn.close()
|
|
print("✅ Database connection successful!")
|
|
sys.exit(0)
|
|
except Exception as e:
|
|
retry_count += 1
|
|
print(f"Database not ready yet (attempt {retry_count}/{max_retries}). Waiting...")
|
|
time.sleep(2)
|
|
|
|
print("❌ Failed to connect to database after 30 attempts")
|
|
sys.exit(1)
|
|
END
|
|
do
|
|
echo "Retrying database connection..."
|
|
sleep 2
|
|
done
|
|
|
|
# Create external_server.conf from environment variables
|
|
echo "Creating database configuration..."
|
|
cat > /app/instance/external_server.conf << EOF
|
|
server_domain=${DB_HOST}
|
|
port=${DB_PORT}
|
|
database_name=${DB_NAME}
|
|
username=${DB_USER}
|
|
password=${DB_PASSWORD}
|
|
EOF
|
|
|
|
echo "✅ Database configuration created"
|
|
|
|
# Run database initialization if needed
|
|
if [ "${INIT_DB}" = "true" ]; then
|
|
echo "Initializing database schema..."
|
|
python3 /app/app/db_create_scripts/setup_complete_database.py || echo "⚠️ Database may already be initialized"
|
|
fi
|
|
|
|
# Seed the database with superadmin user
|
|
if [ "${SEED_DB}" = "true" ]; then
|
|
echo "Seeding database with superadmin user..."
|
|
python3 /app/seed.py || echo "⚠️ Database may already be seeded"
|
|
fi
|
|
|
|
echo "==================================="
|
|
echo "Starting application..."
|
|
echo "==================================="
|
|
|
|
# Execute the CMD
|
|
exec "$@"
|