From e8e4afba13bee22f9e3f553127b4a6ad3057765a Mon Sep 17 00:00:00 2001 From: Philippe Lamy Date: Sat, 8 May 2021 16:58:13 -0400 Subject: [PATCH 1/6] Create default wallets --- build.sh | 2 +- .../prompters/900_bitcoin.js | 2 +- cyphernodeconf_docker/run.sh | 2 +- .../templates/bitcoin/createWallets.sh | 34 +++++++++++++++++++ .../templates/bitcoin/entrypoint.sh | 7 ++++ .../installer/docker/docker-compose.yaml | 8 ++--- .../lightning/c-lightning/entrypoint.sh | 2 +- dist/setup.sh | 17 ++++++++-- 8 files changed, 63 insertions(+), 11 deletions(-) create mode 100755 cyphernodeconf_docker/templates/bitcoin/createWallets.sh create mode 100755 cyphernodeconf_docker/templates/bitcoin/entrypoint.sh diff --git a/build.sh b/build.sh index 5d9f960..b5d93a5 100755 --- a/build.sh +++ b/build.sh @@ -11,7 +11,7 @@ NOTIFIER_VERSION="v0.6.0-dev-local" PROXYCRON_VERSION="v0.6.0-dev-local" OTSCLIENT_VERSION="v0.6.0-dev-local" PYCOIN_VERSION="v0.6.0-dev-local" -BITCOIN_VERSION="v0.20.1" +BITCOIN_VERSION="v0.21.0" LIGHTNING_VERSION="v0.9.1" trace() diff --git a/cyphernodeconf_docker/prompters/900_bitcoin.js b/cyphernodeconf_docker/prompters/900_bitcoin.js index 4dc2a44..a6817ea 100644 --- a/cyphernodeconf_docker/prompters/900_bitcoin.js +++ b/cyphernodeconf_docker/prompters/900_bitcoin.js @@ -104,6 +104,6 @@ module.exports = { return 'VAR0=VALUE0\nVAR1=VALUE1' }, templates: function( props ) { - return ['bitcoin.conf', 'bitcoin-client.conf'] + return ['bitcoin.conf', 'bitcoin-client.conf', 'entrypoint.sh', 'createWallets.sh']; } }; \ No newline at end of file diff --git a/cyphernodeconf_docker/run.sh b/cyphernodeconf_docker/run.sh index bf1c1ae..fa84318 100755 --- a/cyphernodeconf_docker/run.sh +++ b/cyphernodeconf_docker/run.sh @@ -6,7 +6,7 @@ export DEFAULT_CERT_HOSTNAME=disk0book.local export PROXYCRON_VERSION=v0.6.0-dev export PYCOIN_VERSION=v0.6.0-dev export SETUP_VERSION=v0.6.0-dev -export BITCOIN_VERSION=v0.20.1 +export BITCOIN_VERSION=v0.21.0 export LIGHTNING_VERSION=v0.9.1 export DEFAULT_DATADIR_BASE=$HOME export GATEKEEPER_VERSION=v0.6.0-dev diff --git a/cyphernodeconf_docker/templates/bitcoin/createWallets.sh b/cyphernodeconf_docker/templates/bitcoin/createWallets.sh new file mode 100755 index 0000000..c7c3d53 --- /dev/null +++ b/cyphernodeconf_docker/templates/bitcoin/createWallets.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +BITCOIN_CLI='bitcoin-cli' + +<% if( net === 'regtest' ) { %> +BITCOIN_CLI="$BITCOIN_CLI -regtest" +<% } %> + +while [ true ]; +do + sleep 5; + echo "CYPHERNODE: bitcoind is starting" + ${BITCOIN_CLI} echo && touch /container_monitor/bitcoin_ready && break || rm -f /container_monitor/bitcoin_ready +done + +echo "CYPHERNODE: bitcoind is ready" + +# Check for the basic wallets. If not present, create. +BASIC_WALLETS='"watching01.dat" "xpubwatching01.dat" "spending01.dat"' + +CURRENT_WALLETS=`$BITCOIN_CLI listwallets` + +for wallet in $BASIC_WALLETS +do + echo "CYPHERNODE: Checking wallet [$wallet]" + echo "$CURRENT_WALLETS" | grep -F $wallet > /dev/null 2>&1 + + if [ "$?" -ne "0" ]; then + walletNameNoQuote=`echo $wallet | tr -d '"'` + $BITCOIN_CLI createwallet ${walletNameNoQuote} && echo "CYPHERNODE: new wallet created : [$walletNameNoQuote]" + else + echo "CYPHERNODE: Wallet [$wallet] found" + fi +done \ No newline at end of file diff --git a/cyphernodeconf_docker/templates/bitcoin/entrypoint.sh b/cyphernodeconf_docker/templates/bitcoin/entrypoint.sh new file mode 100755 index 0000000..7d547fc --- /dev/null +++ b/cyphernodeconf_docker/templates/bitcoin/entrypoint.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +rm -f /container_monitor/bitcoin_ready + +/.bitcoin/createWallets.sh & + +exec bitcoind diff --git a/cyphernodeconf_docker/templates/installer/docker/docker-compose.yaml b/cyphernodeconf_docker/templates/installer/docker/docker-compose.yaml index 99d0196..30a3616 100644 --- a/cyphernodeconf_docker/templates/installer/docker/docker-compose.yaml +++ b/cyphernodeconf_docker/templates/installer/docker/docker-compose.yaml @@ -73,17 +73,15 @@ services: bitcoin: image: cyphernode/bitcoin:<%= bitcoin_version %> - <% if ( features.indexOf('tor') !== -1 && torifyables && torifyables.indexOf('tor_bitcoin') !== -1 ) { %> - command: $USER sh -c 'rm -f /container_monitor/bitcoin_ready ; while [ ! -f "/container_monitor/tor_ready" ]; do echo "tor not ready" ; sleep 10 ; done ; echo "tor ready" ; bitcoind' - <% } else { %> - command: $USER sh -c 'rm -f /container_monitor/bitcoin_ready ; bitcoind' - <% } %> + command: $USER /.bitcoin/entrypoint.sh <% if( bitcoin_expose ) { %> ports: - "<%= (net === 'regtest') ? '18444:18444' : ((net === 'testnet') ? '18333:18333' : '8333:8333') %>" <% } %> volumes: - "<%= bitcoin_datapath %>:/.bitcoin" + - "<%= bitcoin_datapath %>/entrypoint.sh:/.bitcoin/entrypoint.sh:ro" + - "<%= bitcoin_datapath %>/createWallets.sh:/.bitcoin/createWallets.sh:ro" - container_monitor:/container_monitor healthcheck: test: chown $USER /container_monitor && su-exec $USER sh -c 'bitcoin-cli echo && touch /container_monitor/bitcoin_ready || rm -f /container_monitor/bitcoin_ready' diff --git a/cyphernodeconf_docker/templates/lightning/c-lightning/entrypoint.sh b/cyphernodeconf_docker/templates/lightning/c-lightning/entrypoint.sh index 4b0817a..8b9ec7e 100755 --- a/cyphernodeconf_docker/templates/lightning/c-lightning/entrypoint.sh +++ b/cyphernodeconf_docker/templates/lightning/c-lightning/entrypoint.sh @@ -16,6 +16,6 @@ echo "tor ready at IP ${TORIP}" lightningd --proxy=$TORIP:9050 <% } else { %> -lightningd +exec lightningd <% } %> diff --git a/dist/setup.sh b/dist/setup.sh index 1e73c09..811186d 100755 --- a/dist/setup.sh +++ b/dist/setup.sh @@ -506,6 +506,20 @@ install_docker() { copy_file $cyphernodeconf_filepath/bitcoin/bitcoin-client.conf $BITCOIN_DATAPATH/bitcoin-client.conf 1 $SUDO_REQUIRED fi fi + + copy_file $cyphernodeconf_filepath/bitcoin/entrypoint.sh $BITCOIN_DATAPATH/entrypoint.sh 1 $SUDO_REQUIRED + copy_file $cyphernodeconf_filepath/bitcoin/createWallets.sh $BITCOIN_DATAPATH/createWallets.sh 1 $SUDO_REQUIRED + + if [[ ! -x $BITCOIN_DATAPATH/entrypoint.sh ]]; then + step " make entrypoint.sh executable" + sudo_if_required chmod +x $BITCOIN_DATAPATH/entrypoint.sh + next + fi + if [[ ! -x $BITCOIN_DATAPATH/createWallets.sh ]]; then + step " make createWallets.sh executable" + sudo_if_required chmod +x $BITCOIN_DATAPATH/createWallets.sh + next + fi fi if [[ $FEATURE_LIGHTNING == true ]]; then @@ -529,7 +543,6 @@ install_docker() { sudo_if_required chmod +x $LIGHTNING_DATAPATH/bitcoin/entrypoint.sh next fi - fi fi @@ -838,7 +851,7 @@ PROXYCRON_VERSION="v0.6.0-dev" OTSCLIENT_VERSION="v0.6.0-dev" PYCOIN_VERSION="v0.6.0-dev" CYPHERAPPS_VERSION="dev" -BITCOIN_VERSION="v0.20.1" +BITCOIN_VERSION="v0.21.0" LIGHTNING_VERSION="v0.9.1" TRAEFIK_VERSION="v1.7.9-alpine" MOSQUITTO_VERSION="1.6" From b398d586905d8dc82731fb67d4a32685c403a95b Mon Sep 17 00:00:00 2001 From: Philippe Lamy Date: Mon, 10 May 2021 11:33:53 -0400 Subject: [PATCH 2/6] Added wait loop for tor --- cyphernodeconf_docker/templates/bitcoin/entrypoint.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cyphernodeconf_docker/templates/bitcoin/entrypoint.sh b/cyphernodeconf_docker/templates/bitcoin/entrypoint.sh index 7d547fc..f961a7e 100755 --- a/cyphernodeconf_docker/templates/bitcoin/entrypoint.sh +++ b/cyphernodeconf_docker/templates/bitcoin/entrypoint.sh @@ -2,6 +2,16 @@ rm -f /container_monitor/bitcoin_ready +<% if ( features.indexOf('tor') !== -1 && torifyables && torifyables.indexOf('tor_bitcoin') !== -1 ) { %> +while [ ! -f "/container_monitor/tor_ready" ]; +do + echo "CYPHERNODE: Waiting for Tor to be ready before starting bitcoind" + sleep 10 +done +echo "CYPHERNODE: Tor is ready - Starting bitcoind" +<% } %> + +# Create default wallets if they are not loaded /.bitcoin/createWallets.sh & exec bitcoind From aa11eba2df3526a826a6bb69d936aa72d7844eab Mon Sep 17 00:00:00 2001 From: Philippe Lamy Date: Thu, 13 May 2021 09:56:53 -0400 Subject: [PATCH 3/6] fixe for wait loop --- cyphernodeconf_docker/templates/bitcoin/createWallets.sh | 6 ++++-- .../templates/lightning/c-lightning/entrypoint.sh | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cyphernodeconf_docker/templates/bitcoin/createWallets.sh b/cyphernodeconf_docker/templates/bitcoin/createWallets.sh index c7c3d53..72993f1 100755 --- a/cyphernodeconf_docker/templates/bitcoin/createWallets.sh +++ b/cyphernodeconf_docker/templates/bitcoin/createWallets.sh @@ -6,11 +6,13 @@ BITCOIN_CLI='bitcoin-cli' BITCOIN_CLI="$BITCOIN_CLI -regtest" <% } %> +USER="`id -u -n`:`id -g -n`" + while [ true ]; do - sleep 5; + sleep 10; echo "CYPHERNODE: bitcoind is starting" - ${BITCOIN_CLI} echo && touch /container_monitor/bitcoin_ready && break || rm -f /container_monitor/bitcoin_ready + chown $USER /container_monitor && ${BITCOIN_CLI} echo && touch /container_monitor/bitcoin_ready && chown $USER /container_monitor/bitcoin_ready && break || rm -f /container_monitor/bitcoin_ready done echo "CYPHERNODE: bitcoind is ready" diff --git a/cyphernodeconf_docker/templates/lightning/c-lightning/entrypoint.sh b/cyphernodeconf_docker/templates/lightning/c-lightning/entrypoint.sh index 8b9ec7e..37579e3 100755 --- a/cyphernodeconf_docker/templates/lightning/c-lightning/entrypoint.sh +++ b/cyphernodeconf_docker/templates/lightning/c-lightning/entrypoint.sh @@ -13,7 +13,7 @@ while [ -z "${TORIP}" ]; do echo "tor not ready" ; TORIP=$(getent hosts tor | aw #TORIP=$(getent hosts tor | awk '{ print $1 }') echo "tor ready at IP ${TORIP}" -lightningd --proxy=$TORIP:9050 +exec lightningd --proxy=$TORIP:9050 <% } else { %> exec lightningd From 4be7a2f69bb773eaecb021332323690ff336a579 Mon Sep 17 00:00:00 2001 From: Philippe Lamy Date: Thu, 13 May 2021 09:57:54 -0400 Subject: [PATCH 4/6] removed useless volume --- .../templates/installer/docker/docker-compose.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/cyphernodeconf_docker/templates/installer/docker/docker-compose.yaml b/cyphernodeconf_docker/templates/installer/docker/docker-compose.yaml index 30a3616..ecf718b 100644 --- a/cyphernodeconf_docker/templates/installer/docker/docker-compose.yaml +++ b/cyphernodeconf_docker/templates/installer/docker/docker-compose.yaml @@ -80,7 +80,6 @@ services: <% } %> volumes: - "<%= bitcoin_datapath %>:/.bitcoin" - - "<%= bitcoin_datapath %>/entrypoint.sh:/.bitcoin/entrypoint.sh:ro" - "<%= bitcoin_datapath %>/createWallets.sh:/.bitcoin/createWallets.sh:ro" - container_monitor:/container_monitor healthcheck: From cef7186122616925e8fe2802d52cfea92fc28f6f Mon Sep 17 00:00:00 2001 From: Philippe Lamy Date: Fri, 14 May 2021 10:14:51 -0400 Subject: [PATCH 5/6] fix to get id+group of current user --- cyphernodeconf_docker/templates/bitcoin/createWallets.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cyphernodeconf_docker/templates/bitcoin/createWallets.sh b/cyphernodeconf_docker/templates/bitcoin/createWallets.sh index 72993f1..0d97ee6 100755 --- a/cyphernodeconf_docker/templates/bitcoin/createWallets.sh +++ b/cyphernodeconf_docker/templates/bitcoin/createWallets.sh @@ -6,7 +6,7 @@ BITCOIN_CLI='bitcoin-cli' BITCOIN_CLI="$BITCOIN_CLI -regtest" <% } %> -USER="`id -u -n`:`id -g -n`" +USER="`id -u`:`id -g`" while [ true ]; do From 3aea4e7cadba0be7e9f9477fb9d14e57b39a1c2a Mon Sep 17 00:00:00 2001 From: Philippe Lamy Date: Thu, 20 May 2021 12:24:47 -0400 Subject: [PATCH 6/6] Changed wait loop for bitcoind after jedi review --- cyphernodeconf_docker/templates/bitcoin/createWallets.sh | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/cyphernodeconf_docker/templates/bitcoin/createWallets.sh b/cyphernodeconf_docker/templates/bitcoin/createWallets.sh index 0d97ee6..699d293 100755 --- a/cyphernodeconf_docker/templates/bitcoin/createWallets.sh +++ b/cyphernodeconf_docker/templates/bitcoin/createWallets.sh @@ -6,14 +6,7 @@ BITCOIN_CLI='bitcoin-cli' BITCOIN_CLI="$BITCOIN_CLI -regtest" <% } %> -USER="`id -u`:`id -g`" - -while [ true ]; -do - sleep 10; - echo "CYPHERNODE: bitcoind is starting" - chown $USER /container_monitor && ${BITCOIN_CLI} echo && touch /container_monitor/bitcoin_ready && chown $USER /container_monitor/bitcoin_ready && break || rm -f /container_monitor/bitcoin_ready -done +while [ ! -f "/container_monitor/bitcoin_ready" ]; do echo "CYPHERNODE: bitcoind not ready" ; sleep 10 ; done echo "CYPHERNODE: bitcoind is ready"