-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
poll for RPC socket availability before launching ln nodes
- Loading branch information
Showing
3 changed files
with
32 additions
and
6 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
recipes/cookbook/scaffold/docker/_aux/runtime/lib/utils.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |