fix: apache starts immediately, db import runs in background
This commit is contained in:
+30
-19
@@ -1,29 +1,40 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
|
||||||
|
|
||||||
echo "=== Starting WebGIS Application ==="
|
echo "=== Starting WebGIS Application ==="
|
||||||
|
|
||||||
# Tunggu MySQL siap
|
# Jalankan setup database di background (tidak blokir Apache)
|
||||||
echo "Waiting for MySQL at $DB_HOST..."
|
(
|
||||||
until mysql -h"$DB_HOST" -uroot -p"$DB_PASS" -e "SELECT 1" > /dev/null 2>&1; do
|
echo "Background: Waiting for MySQL at $DB_HOST..."
|
||||||
echo "MySQL not ready yet, retrying in 3s..."
|
MAX_TRIES=30
|
||||||
sleep 3
|
COUNT=0
|
||||||
done
|
until mysql -h"$DB_HOST" -uroot -p"$DB_PASS" -e "SELECT 1" > /dev/null 2>&1; do
|
||||||
echo "MySQL is ready!"
|
COUNT=$((COUNT+1))
|
||||||
|
if [ $COUNT -ge $MAX_TRIES ]; then
|
||||||
|
echo "Background: MySQL timeout, skipping DB setup."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
echo "Background: MySQL not ready ($COUNT/$MAX_TRIES), retrying..."
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
|
|
||||||
# Setup database webgis (sudah ada CREATE DATABASE di dalam file SQL)
|
echo "Background: MySQL ready! Setting up databases..."
|
||||||
echo "Setting up webgis database..."
|
|
||||||
mysql -h"$DB_HOST" -uroot -p"$DB_PASS" < /var/www/html/WEBGIS/01/api/setup_webgis.sql && echo "webgis OK!" || echo "webgis already exists, skipping."
|
|
||||||
|
|
||||||
# Buat database kemiskinan_ibadah jika belum ada
|
mysql -h"$DB_HOST" -uroot -p"$DB_PASS" < /var/www/html/WEBGIS/01/api/setup_webgis.sql \
|
||||||
echo "Creating kemiskinan_ibadah database..."
|
&& echo "Background: webgis OK!" \
|
||||||
mysql -h"$DB_HOST" -uroot -p"$DB_PASS" -e "CREATE DATABASE IF NOT EXISTS kemiskinan_ibadah CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
|
|| echo "Background: webgis already exists, skipped."
|
||||||
|
|
||||||
# Import tabel ke kemiskinan_ibadah
|
mysql -h"$DB_HOST" -uroot -p"$DB_PASS" \
|
||||||
echo "Importing kemiskinan_ibadah tables..."
|
-e "CREATE DATABASE IF NOT EXISTS kemiskinan_ibadah CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
|
||||||
mysql -h"$DB_HOST" -uroot -p"$DB_PASS" kemiskinan_ibadah < /var/www/html/webtugas/01/api/setup_webtugas.sql && echo "kemiskinan_ibadah OK!" || echo "kemiskinan_ibadah import done (may already exist)."
|
|
||||||
|
|
||||||
echo "=== Database setup complete, starting Apache ==="
|
mysql -h"$DB_HOST" -uroot -p"$DB_PASS" kemiskinan_ibadah \
|
||||||
|
< /var/www/html/webtugas/01/api/setup_webtugas.sql \
|
||||||
|
&& echo "Background: kemiskinan_ibadah OK!" \
|
||||||
|
|| echo "Background: kemiskinan_ibadah already exists, skipped."
|
||||||
|
|
||||||
# Jalankan Apache
|
echo "Background: === Database setup complete ==="
|
||||||
|
) &
|
||||||
|
|
||||||
|
echo "=== Starting Apache now ==="
|
||||||
|
|
||||||
|
# Start Apache langsung (tidak tunggu DB)
|
||||||
exec apache2-foreground
|
exec apache2-foreground
|
||||||
|
|||||||
Reference in New Issue
Block a user