From e52331fe619f2b3c54f67230ae7ca74a5d61dbec Mon Sep 17 00:00:00 2001 From: kexkey Date: Sat, 18 Jan 2020 14:43:00 -0500 Subject: [PATCH] readiness monitor for tor, lightning, bitcoin... --- cyphernodeconf_docker/lib/app.js | 8 +++-- cyphernodeconf_docker/run.sh | 4 +++ .../installer/docker/docker-compose.yaml | 33 ++++++++++++------- .../templates/installer/testdeployment.sh | 4 +-- .../templates/installer/testfeatures.sh | 8 ++++- .../lightning/c-lightning/entrypoint.sh | 10 ++++-- dist/setup.sh | 4 +++ doc/README.md | 2 +- docker-compose-sample.yml | 10 +++--- 9 files changed, 58 insertions(+), 25 deletions(-) diff --git a/cyphernodeconf_docker/lib/app.js b/cyphernodeconf_docker/lib/app.js index 1ba1331..54cbba5 100644 --- a/cyphernodeconf_docker/lib/app.js +++ b/cyphernodeconf_docker/lib/app.js @@ -87,6 +87,8 @@ module.exports = class App { proxy_version: process.env.PROXY_VERSION, proxycron_version: process.env.PROXYCRON_VERSION, pycoin_version: process.env.PYCOIN_VERSION, + traefik_version: process.env.TRAEFIK_VERSION, + mosquitto_version: process.env.MOSQUITTO_VERSION, otsclient_version: process.env.OTSCLIENT_VERSION, bitcoin_version: process.env.BITCOIN_VERSION, lightning_version: process.env.LIGHTNING_VERSION, @@ -146,10 +148,10 @@ module.exports = class App { 'cyphernode/proxycron': this.sessionData.proxycron_version, 'cyphernode/pycoin': this.sessionData.pycoin_version, 'cyphernode/otsclient': this.sessionData.otsclient_version, + 'traefik': this.sessionData.traefik_version, 'cyphernode/clightning': this.sessionData.lightning_version, 'cyphernode/notifier': this.sessionData.notifier_version, - 'traefik': 'v1.7.9-alpine', - 'eclipse-mosquitto': '1.6' + 'eclipse-mosquitto': this.sessionData.mosquitto_version } } ); @@ -498,7 +500,7 @@ module.exports = class App { label: 'traefik', host: 'traefik', networks: ['cyphernodeappsnet'], - docker: 'cyphernode/traefik:'+this.config.docker_versions['cyphernode/traefik'], + docker: 'traefik:'+this.config.docker_versions['traefik'], extra: { tor_hostname: this.sessionData.tor_traefik_hostname, } diff --git a/cyphernodeconf_docker/run.sh b/cyphernodeconf_docker/run.sh index 6c1afc9..edcd009 100755 --- a/cyphernodeconf_docker/run.sh +++ b/cyphernodeconf_docker/run.sh @@ -15,6 +15,8 @@ export PROXY_VERSION=v0.2.4 export OTSCLIENT_VERSION=v0.2.4 export NOTIFIER_VERSION=v0.2.4 export EDITOR=/usr/bin/nano +export TRAEFIK_VERSION="v1.7.9-alpine" +export MOSQUITTO_VERSION="1.6" user=$(id -u):$(id -g) @@ -26,6 +28,8 @@ if [ "${MODE}" = 'docker' ]; then -e SETUP_DIR=$SETUP_DIR \ -e DEFAULT_CERT_HOSTNAME=$(hostname) \ -e GATEKEEPER_VERSION=$GATEKEEPER_VERSION \ + -e TRAEFIK_VERSION=$TRAEFIK_VERSION \ + -e MOSQUITTO_VERSION=$MOSQUITTO_VERSION \ -e TOR_VERSION=$TOR_VERSION \ -e PROXY_VERSION=$PROXY_VERSION \ -e NOTIFIER_VERSION=$NOTIFIER_VERSION \ diff --git a/cyphernodeconf_docker/templates/installer/docker/docker-compose.yaml b/cyphernodeconf_docker/templates/installer/docker/docker-compose.yaml index 9e7a349..93b2450 100644 --- a/cyphernodeconf_docker/templates/installer/docker/docker-compose.yaml +++ b/cyphernodeconf_docker/templates/installer/docker/docker-compose.yaml @@ -10,13 +10,19 @@ services: tor: image: cyphernode/tor:<%= tor_version %> # Sleeping 7 seconds to let lightning and traefik start - command: $USER sh -c 'sleep 7 ; export HOME=/tor ; tor -f /tor/torrc' + command: $USER sh -c 'rm -f /container_monitor/tor_ready ; sleep 10 ; export HOME=/tor ; tor -f /tor/torrc' volumes: - "<%= tor_datapath %>:/tor" - restart: always + - container_monitor:/container_monitor + healthcheck: + test: chown $USER /container_monitor && su-exec $USER sh -c 'tor-resolve torproject.org && touch /container_monitor/tor_ready && chown $USER /container_monitor/tor_ready || rm -f /container_monitor/tor_ready' + interval: 20s + timeout: 10s + retries: 10 networks: - cyphernodenet - cyphernodeappsnet + restart: always # deploy: # placement: # constraints: [node.hostname==dev] @@ -37,7 +43,12 @@ services: volumes: - "<%= lightning_datapath %>:/.lightning" - "<%= bitcoin_datapath %>/bitcoin-client.conf:/.bitcoin/bitcoin.conf:ro" - - bitcoin_monitor:/bitcoin_monitor:ro + - container_monitor:/container_monitor + healthcheck: + test: chown $USER /container_monitor && su-exec $USER sh -c 'lightning-cli getinfo && touch /container_monitor/lightning_ready && chown $USER /container_monitor/lightning_ready || rm -f /container_monitor/lightning_ready' + interval: 20s + timeout: 10s + retries: 10 networks: - cyphernodenet restart: always @@ -45,7 +56,7 @@ services: depends_on: - tor <% } %> -# deploy: +# deploy: --lightning-dir=/.lightning # placement: # constraints: [node.hostname==dev] <% } %> @@ -57,7 +68,7 @@ services: bitcoin: image: cyphernode/bitcoin:<%= bitcoin_version %> - command: $USER bitcoind + 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' <% if( bitcoin_expose ) { %> ports: - "<%= (net === 'regtest') ? '18443:18443' : ((net === 'testnet') ? '18332:18332' : '8332:8332') %>" @@ -65,11 +76,11 @@ services: <% } %> volumes: - "<%= bitcoin_datapath %>:/.bitcoin" - - bitcoin_monitor:/bitcoin_monitor + - container_monitor:/container_monitor healthcheck: - test: bitcoin-cli echo && touch /bitcoin_monitor/up || rm -f /bitcoin_monitor/up + test: chown $USER /container_monitor && su-exec $USER sh -c 'bitcoin-cli echo && touch /container_monitor/bitcoin_ready || rm -f /container_monitor/bitcoin_ready' interval: 20s - timeout: 5s + timeout: 10s retries: 10 networks: - cyphernodenet @@ -158,7 +169,7 @@ services: ########################## broker: - image: eclipse-mosquitto:1.6 + image: eclipse-mosquitto:<%= mosquitto_version %> networks: - cyphernodenet - cyphernodeappsnet @@ -279,7 +290,7 @@ services: ########################## traefik: - image: traefik:v1.7.9-alpine + image: traefik:<%= traefik_version %> ports: - <%= traefik_http_port %>:<%= traefik_http_port %> - <%= traefik_https_port %>:<%= traefik_https_port %> @@ -298,7 +309,7 @@ services: # constraints: [node.hostname==dev] volumes: - bitcoin_monitor: + container_monitor: networks: cyphernodenet: diff --git a/cyphernodeconf_docker/templates/installer/testdeployment.sh b/cyphernodeconf_docker/templates/installer/testdeployment.sh index 8d00d56..731d504 100644 --- a/cyphernodeconf_docker/templates/installer/testdeployment.sh +++ b/cyphernodeconf_docker/templates/installer/testdeployment.sh @@ -57,8 +57,8 @@ current_path="$(cd "$(dirname "$0")" >/dev/null && pwd)" docker run --rm -it -v $current_path/testfeatures.sh:/testfeatures.sh \ -v <%= gatekeeper_datapath %>:/gatekeeper \ -v $current_path:/dist \ --v cyphernode_bitcoin_monitor:/bitcoin_monitor:ro \ ---network cyphernodenet eclipse-mosquitto:1.6.2 /testfeatures.sh +-v cyphernode_container_monitor:/container_monitor:ro \ +--network cyphernodenet eclipse-mosquitto:<%= mosquitto_version %> /testfeatures.sh if [ -f $current_path/exitStatus.sh ]; then . $current_path/exitStatus.sh diff --git a/cyphernodeconf_docker/templates/installer/testfeatures.sh b/cyphernodeconf_docker/templates/installer/testfeatures.sh index 083e581..57a6575 100644 --- a/cyphernodeconf_docker/templates/installer/testfeatures.sh +++ b/cyphernodeconf_docker/templates/installer/testfeatures.sh @@ -387,6 +387,9 @@ result="${result}$(feature_status ${returncode} 'OTSclient error!')}" # TOR # ############################# +echo -e "\r\n\e[1;36mWaiting for Tor to be ready... " > /dev/console +timeout_feature '[ -f "/container_monitor/tor_ready" ]' + result="${result},{\"coreFeature\":false, \"name\":\"tor\",\"working\":" status=$(echo "{${containers}}" | jq ".containers[] | select(.name == \"tor\") | .active") if [[ "${workingproxy}" = "true" && "${status}" = "true" ]]; then @@ -404,7 +407,7 @@ result="${result}$(feature_status ${returncode} 'Tor error!')}" ############################# echo -e "\r\n\e[1;36mWaiting for Bitcoin Core to be ready... " > /dev/console -timeout_feature '[ -f "/bitcoin_monitor/up" ]' +timeout_feature '[ -f "/container_monitor/bitcoin_ready" ]' result="${result},{\"coreFeature\":true, \"name\":\"bitcoin\",\"working\":" status=$(echo "{${containers}}" | jq ".containers[] | select(.name == \"bitcoin\") | .active") @@ -422,6 +425,9 @@ result="${result}$(feature_status ${returncode} 'Bitcoin error!')}" # LIGHTNING # ############################# +echo -e "\r\n\e[1;36mWaiting for C-Lightning to be ready... " > /dev/console +timeout_feature '[ -f "/container_monitor/lightning_ready" ]' + result="${result},{\"coreFeature\":false, \"name\":\"lightning\",\"working\":" status=$(echo "{${containers}}" | jq ".containers[] | select(.name == \"lightning\") | .active") if [[ "${workingproxy}" = "true" && "${status}" = "true" ]]; then diff --git a/cyphernodeconf_docker/templates/lightning/c-lightning/entrypoint.sh b/cyphernodeconf_docker/templates/lightning/c-lightning/entrypoint.sh index c446a71..f5da5aa 100755 --- a/cyphernodeconf_docker/templates/lightning/c-lightning/entrypoint.sh +++ b/cyphernodeconf_docker/templates/lightning/c-lightning/entrypoint.sh @@ -1,11 +1,17 @@ #!/bin/sh -while [ ! -f "/bitcoin_monitor/up" ]; do echo "bitcoin not ready" ; sleep 10 ; done +rm -f /container_monitor/lightning_ready + +while [ ! -f "/container_monitor/bitcoin_ready" ]; do echo "bitcoin not ready" ; sleep 10 ; done + +echo "bitcoin ready" <% if ( torifyables.indexOf('tor_ln') !== -1 ) { %> +#while [ ! -f "/container_monitor/tor_ready" ]; do echo "tor not ready" ; sleep 10 ; done while [ -z "${TORIP}" ]; do echo "tor not ready" ; TORIP=$(getent hosts tor | awk '{ print $1 }') ; sleep 10 ; done -echo "Tor ready at IP ${TORIP}" +#TORIP=$(getent hosts tor | awk '{ print $1 }') +echo "tor ready at IP ${TORIP}" lightningd --proxy=$TORIP:9050 <% } else { %> diff --git a/dist/setup.sh b/dist/setup.sh index a630328..f3961d8 100755 --- a/dist/setup.sh +++ b/dist/setup.sh @@ -185,6 +185,8 @@ configure() { -e SETUP_DIR=$SETUP_DIR \ -e DEFAULT_CERT_HOSTNAME=$(hostname) \ -e GATEKEEPER_VERSION=$GATEKEEPER_VERSION \ + -e TRAEFIK_VERSION=$TRAEFIK_VERSION \ + -e MOSQUITTO_VERSION=$MOSQUITTO_VERSION \ -e TOR_VERSION=$TOR_VERSION \ -e PROXY_VERSION=$PROXY_VERSION \ -e NOTIFIER_VERSION=$NOTIFIER_VERSION \ @@ -787,6 +789,8 @@ PYCOIN_VERSION="v0.2.4" CYPHERAPPS_VERSION="dev" BITCOIN_VERSION="v0.19.0.1" LIGHTNING_VERSION="v0.8.0" +TRAEFIK_VERSION="v1.7.9-alpine" +MOSQUITTO_VERSION="1.6" SETUP_DIR=$(dirname $(realpath $0)) diff --git a/doc/README.md b/doc/README.md index 023c06a..0b5293e 100644 --- a/doc/README.md +++ b/doc/README.md @@ -44,7 +44,7 @@ Current components in Cyphernode: - Bitcoin: Bitcoin Core node. Cyphernode uses a watching wallet for watchers (no funds) and a spending wallet for spending. Mandatory component, but optionally part of Cyphernode installation, as we can use an already running Bitcoin Core node. - Lightning: optional. C-Lightning node. The LN node will use the Bitcoin node for its tasks. - OTSclient: optional. Used to stamp hashes on the Bitcoin blockchain. -- Tor: optional. Used to serve traefik as a HiddenService as well as Internet Gateway. +- Tor: optional. Used to serve traefik, bitcoin and/or lightning as a HiddenService as well as Internet Gateway. Future components: diff --git a/docker-compose-sample.yml b/docker-compose-sample.yml index 16dbb3b..a334f6a 100644 --- a/docker-compose-sample.yml +++ b/docker-compose-sample.yml @@ -13,9 +13,9 @@ services: volumes: - "~/btcdata:/.bitcoin" - - bitcoin_monitor:/bitcoin_monitor + - container_monitor:/container_monitor healthcheck: - test: bitcoin-cli echo && touch /bitcoin_monitor/up || rm -f /bitcoin_monitor/up + test: bitcoin-cli echo && touch /container_monitor/bitcoin_ready || rm -f /container_monitor/bitcoin_ready interval: 10s timeout: 5s retries: 1 @@ -226,7 +226,7 @@ services: lightning: image: cyphernode/clightning:v0.8.0 - command: $USER sh -c 'while [ ! -f "/bitcoin_monitor/up" ]; do echo "bitcoin not ready" ; sleep 10 ; done ; echo "bitcoin ready!" ; lightningd' + command: $USER sh -c 'while [ ! -f "/container_monitor/bitcoin_ready" ]; do echo "bitcoin not ready" ; sleep 10 ; done ; echo "bitcoin ready!" ; lightningd' ports: - "9735:9735" @@ -234,7 +234,7 @@ services: volumes: - "~/cn-dev/dist/cyphernode/lightning:/.lightning" - "~/btcdata/bitcoin-client.conf:/.bitcoin/bitcoin.conf" - - bitcoin_monitor:/bitcoin_monitor:ro + - container_monitor:/container_monitor:ro networks: - cyphernodenet restart: always @@ -246,7 +246,7 @@ services: volumes: - bitcoin_monitor: + container_monitor: networks: cyphernodenet: