Skip to content

Commit

Permalink
poll for RPC socket availability before launching ln nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
darwin committed Apr 30, 2019
1 parent 8bf92ee commit 8c84fd0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
20 changes: 20 additions & 0 deletions recipes/cookbook/scaffold/docker/_aux/runtime/lib/utils.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
#!/usr/bin/env bash

echo_err() {
printf "\e[31m%s\e[0m\n" "$*" >&2;
}

wait_for_socket() {
local port=${1:?required}
local host=${2:-localhost}
local max=${3:-100}
local delay=${4:-1}

local counter=1
while ! nc -z "$host" "$port" > /dev/null 2>&1; do
sleep ${delay}
((++counter))
if [[ ${counter} -gt ${max} ]]; then
echo_err "socket '$host:$port' didn't come online in time"
return 1
fi
done
}
9 changes: 6 additions & 3 deletions recipes/cookbook/scaffold/docker/lightning/home/start.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env bash

# give bitcoin nodes some head start
# TODO: revisit this
sleep 10
. lib/utils.sh

# wait for bitcoin node to open its RPC interface
LIGHTNING_BITCOIN_RPC_HOST=${LIGHTNING_BITCOIN_RPC_HOST:?required}
BITCOIN_RPC_PORT=${BITCOIN_RPC_PORT:?required}
wait_for_socket "$BITCOIN_RPC_PORT" "$LIGHTNING_BITCOIN_RPC_HOST"

exec lightningd.sh
9 changes: 6 additions & 3 deletions recipes/cookbook/scaffold/docker/lnd/home/start.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/usr/bin/env bash

# give bitcoin nodes some head start
# TODO: revisit this
sleep 10
. lib/utils.sh

# wait for shared certificate creation
while [[ ! -f /certs/rpc.cert ]]; do sleep 1; done

# wait for bitcoin node to open its RPC interface
LND_BITCOIN_RPC_HOST=${LND_BITCOIN_RPC_HOST:?required}
BITCOIN_RPC_PORT=${BITCOIN_RPC_PORT:?required}
wait_for_socket "$BITCOIN_RPC_PORT" "$LND_BITCOIN_RPC_HOST"

exec lnd.sh

0 comments on commit 8c84fd0

Please sign in to comment.