Skip to content

Commit

Permalink
- attempt to make wait for DB mechanism to work with sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
cioraneanu committed Oct 21, 2024
1 parent 4fc2d00 commit 9453a90
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions docker/docker-entrypoint.d/start.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
#!/bin/sh

while true; do
if nc -z -w 5 $DB_HOST $DB_PORT; then
echo "Successfully connected to DB"
break
# Check if $DB_HOST is a Unix socket (starts with "/")
if echo "$DB_HOST" | grep -q "^/"; then
# Unix socket connection
if [ -S "$DB_HOST" ]; then
echo "Successfully connected to DB via Unix socket: $DB_HOST"
break
else
echo "Failed to connect to DB via Unix socket: $DB_HOST. Retrying in 10 seconds..."
fi
else
echo "Failed to connect to DB. Retrying in 10 seconds..."
sleep 10
# TCP connection
if nc -z -w 5 $DB_HOST $DB_PORT; then
echo "Successfully connected to DB via TCP: $DB_HOST:$DB_PORT"
break
else
echo "Failed to connect to DB via TCP: $DB_HOST:$DB_PORT. Retrying in 10 seconds..."
fi
fi

# Wait before retrying
sleep 10
done

php /var/www/html/artisan migrate --isolated --force
Expand Down

0 comments on commit 9453a90

Please sign in to comment.