-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from LN-Zap/delay-lnd-startup
Wait for lnd and stagger startup time for lndk
- Loading branch information
Showing
4 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
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,4 +1,5 @@ | ||
rpclisten=0.0.0.0:10009 | ||
restlisten=0.0.0.0:8080 | ||
trickledelay=1000 | ||
noseedbackup=true | ||
debuglevel=debug | ||
|
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
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,16 +1,30 @@ | ||
#!/bin/bash | ||
|
||
# Usage: | ||
# wait-for-bitcoind.sh <cln-args> | ||
# | ||
# Arguments: | ||
# cln-args The arguments to be passed to the lightningd command. | ||
# | ||
# This script is used to delay the startup of cln nodes until bitcoind is ready. | ||
# It uses the bitcoin-cli command to check the status of bitcoind. | ||
# Once bitcoind is ready, it starts the cln nodes with the provided arguments. | ||
|
||
# Function to check if bitcoind is ready | ||
is_bitcoind_ready() { | ||
bitcoin-cli -rpcconnect=bitcoind -rpcport=43782 -rpcuser=user -rpcpassword=pass -conf=/root/.lightning/bitcoin/bitcoin.conf getblockchaininfo &> /dev/null | ||
return $? | ||
} | ||
|
||
# Wait for bitcoind to be ready | ||
# The until loop will keep looping as long as the is_bitcoind_ready function returns a non-zero value (i.e., bitcoind is not ready). | ||
until is_bitcoind_ready; do | ||
echo "Waiting for bitcoind to be ready..." | ||
# The sleep command is used to pause the script for 5 seconds between each check. | ||
sleep 5 | ||
done | ||
|
||
# Start cln | ||
# The exec command is used to replace the current shell process with the lightningd command. | ||
# The "$@" part is used to pass all arguments to the lightningd command. | ||
exec lightningd "$@" |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/bash | ||
|
||
# Usage: | ||
# wait-for-lnd.sh <host> <delay> <lndk-args> | ||
# | ||
# Arguments: | ||
# host The host of the lnd's gRPC service. | ||
# delay The delay (in seconds) for the startup of lndk nodes after lnd's gRPC port is ready. | ||
# lndk-args The arguments to be passed to the lndk command. | ||
|
||
is_lnd_ready() { | ||
macaroon=$(base64 /root/.lnd/data/chain/bitcoin/regtest/readonly.macaroon | tr -d '\n') | ||
response=$(curl --cacert /root/.lnd/tls.cert -Ss -H "Grpc-Metadata-macaroon: $macaroon" "https://$1:8080/v1/state") | ||
if [ $? -ne 0 ]; then | ||
echo "Error: curl command failed" | ||
echo "Response from curl: $response" | ||
return 1 | ||
fi | ||
if echo "$response" | grep -q '"state":"SERVER_ACTIVE"'; then | ||
return 0 | ||
else | ||
echo "Error: lnd node state is not SERVER_ACTIVE" | ||
echo "Response from lnd: $response" | ||
return 1 | ||
fi | ||
} | ||
|
||
# Wait for lnd to be ready | ||
# The until loop will keep looping as long as the is_lnd_ready function returns a non-zero value (i.e., the port is not open). | ||
until is_lnd_ready $1; do | ||
echo "Waiting for lnd to be ready..." | ||
sleep 2 | ||
done | ||
|
||
# Start lndk | ||
# The exec command is used to replace the current shell process with the lndk command. | ||
# The "${@:3}" part is used to pass all arguments starting from the third one to the lndk command. | ||
exec lndk "${@:2}" |