Skip to content

Commit

Permalink
fix: consolidate service wait conditions and improve reliability
Browse files Browse the repository at this point in the history
Co-Authored-By: Nico Krause <[email protected]>
  • Loading branch information
devin-ai-integration[bot] and silkroadnomad committed Dec 23, 2024
1 parent 38fd4dd commit 112533b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docker-compose-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ services:
volumes:
- ./docker/entrypoint.sh:/usr/src/app/entrypoint.sh
# - ./:/usr/src/app/
entrypoint: ["/bin/sh", "-c", "while ! nc -z electrumx 8443 || ! nc -z regtest 18443; do echo 'Waiting for services...'; sleep 5; done && sleep 15 && /usr/src/app/entrypoint.sh generate-key"]
entrypoint: ["/usr/src/app/entrypoint.sh", "generate-key"]
depends_on:
- electrumx
- regtest
Expand Down
34 changes: 17 additions & 17 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
#!/bin/bash
rm -f scanning-state.json

# Function to check if ElectrumX is ready
check_electrumx() {
nc -z electrumx 8443 2>/dev/null
# Function to check if services are ready
check_services() {
nc -z electrumx 8443 2>/dev/null && nc -z regtest 18443 2>/dev/null
return $?
}

# Function to wait for ElectrumX with timeout
wait_for_electrumx() {
echo "Waiting for ElectrumX to be ready..."
local timeout=60
# Function to wait for services with timeout
wait_for_services() {
echo "Waiting for services to be ready..."
local timeout=120
local count=0
while ! check_electrumx; do
while ! check_services; do
count=$((count + 1))
if [ $count -gt $timeout ]; then
echo "Timeout waiting for ElectrumX"
echo "Timeout waiting for services"
return 1
fi
echo "Attempt $count/$timeout: ElectrumX not ready yet..."
echo "Attempt $count/$timeout: Services not ready yet..."
sleep 1
done
echo "ElectrumX is ready!"
echo "All services are ready!"
return 0
}

Expand All @@ -40,21 +40,21 @@ if [ "$1" == "generate-key" ]; then
fi
cat .env

# Wait for ElectrumX to be ready before starting
if wait_for_electrumx; then
# Wait for all services to be ready before starting
if wait_for_services; then
echo "Starting relay service..."
npm run start
else
echo "Failed to connect to ElectrumX"
echo "Failed to connect to required services"
exit 1
fi
elif [ "$1" == "start" ]; then
echo "Starting node..."
# Wait for ElectrumX to be ready before starting
if wait_for_electrumx; then
# Wait for all services to be ready before starting
if wait_for_services; then
npm run start
else
echo "Failed to connect to ElectrumX"
echo "Failed to connect to required services"
exit 1
fi
else
Expand Down

0 comments on commit 112533b

Please sign in to comment.