-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
79 lines (62 loc) · 2.13 KB
/
Copy pathdocker-entrypoint.sh
File metadata and controls
79 lines (62 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
set -e
# Function to wait for database
wait_for_database() {
echo "⏳ Waiting for database..."
# Check if database environment variables are set
if [ -z "$DB_HOST" ] || [ "$DB_HOST" = "localhost" ] || [ "$DB_HOST" = "127.0.0.1" ]; then
echo "ℹ️ No external database configured, skipping database wait"
return 0
fi
# Wait for database connection
max_attempts=30
attempt=1
until [ $attempt -eq $max_attempts ]; do
# Check if db:monitor returns OK for mysql
if php artisan db:monitor --databases=mysql 2>/dev/null | grep "mysql" | grep -q "OK"; then
echo "✅ Database connection established!"
return 0
fi
echo "⚠️ Database not ready yet... attempt $attempt/$max_attempts"
attempt=$((attempt + 1))
sleep 3
done
echo "❌ ERROR: Could not connect to database after $max_attempts attempts"
exit 1
}
# Your initialization function
init_laravel() {
echo "🚀 Initializing Laravel application..."
# Ensure we're in the right directory
cd /var/www/html
# Check if Laravel is properly installed
if [ ! -f "artisan" ]; then
echo "❌ Laravel artisan file not found!"
exit 1
fi
# Wait for database to be ready (if using database)
wait_for_database
# Run migrations
echo "🔄 Running migrations..."
php artisan migrate --force || {
echo "⚠️ Migration failed, but continuing..."
}
# Create laravel.log file if it doesn't exist
echo "📝 Creating laravel.log file..."
if [ ! -f "storage/logs/laravel.log" ]; then
touch storage/logs/laravel.log
fi
# Run init command
echo "🚀 Running init command..."
php artisan app:init || {
echo "⚠️ Init command failed, but continuing..."
}
# Set file ownership to apache
echo "🔧 Setting file ownership to apache..."
chown -R apache:apache /var/www/html
echo "✅ Laravel initialization completed!"
}
# Run initialization
init_laravel
# Execute the original command
exec "$@"