kiit-kaffe / docker-entrypoint.sh
Kush-Singh-26
Fix database initialization in Docker
474aa28
Raw
History Blame Contribute Delete
1.2 kB
#!/bin/bash
set -e
echo "=== Starting KIIT-KAFE Docker Container ==="
# Initialize MySQL data directory if not exists
if [ ! -d "/var/lib/mysql" ]; then
echo "Initializing MySQL data directory..."
mysql_install_db --user=mysql --datadir=/var/lib/mysql
fi
# Start MySQL server
echo "Starting MySQL server..."
mysqld_safe --user=mysql &
# Wait for MySQL to be ready
echo "Waiting for MySQL to be ready..."
for i in {1..30}; do
if mysql -u root -e "SELECT 1" &>/dev/null; then
echo "MySQL is ready!"
break
fi
echo "Waiting... ($i/30)"
sleep 1
done
# Create database and user directly in entrypoint
echo "Setting up database..."
mysql -u root <<EOF
CREATE DATABASE IF NOT EXISTS kiit_kaffe_db;
USE kiit_kaffe_db;
EOF
# Create database using the project's setup script
echo "Running database setup..."
cd /var/www/html
# Wait a bit more for MySQL to fully initialize
sleep 2
# Use curl to trigger the setup script
# The setup script will create tables and data
curl -s http://localhost:7860/api/setup_db.php || echo "Setup script executed"
# Start Apache in foreground (required for Docker)
echo "Starting Apache on port 7860..."
exec apache2-foreground