diff --git a/readme.md b/readme.md index d51f7c2..19294b5 100644 --- a/readme.md +++ b/readme.md @@ -70,6 +70,7 @@ The following environment variables control the configuration - `READY_FILE` (optional; wait for a file to be created before starting all services, e.g. to wait for chain synchronization) - `REMOVE_LOCK_FILES` (optional; remove leftover lockfiles from possible unclean shutdowns on startup) - `RESTORE_DEFAULT_CONFIG` (optional; overwrites any existing `joinmarket.cfg` file the container's default config on startup) +- `WAIT_FOR_BITCOIND` (optional; wait for bitcoind to accept RPC request and report >= 100 blocks) Variables starting with prefix `JM_` will be applied to `joinmarket.cfg` e.g.: - `JM_GAPLIMIT: 2000` will set the `gaplimit` config value to `2000` @@ -110,6 +111,7 @@ docker run --rm -it \ --env ENSURE_WALLET="true" \ --env REMOVE_LOCK_FILES="true" \ --env RESTORE_DEFAULT_CONFIG="true" \ + --env WAIT_FOR_BITCOIND="true" \ --volume jmdatadir:/root/.joinmarket \ --publish "8080:80" \ joinmarket-webui/jam-standalone diff --git a/standalone/Dockerfile b/standalone/Dockerfile index 0b650e6..7c637b4 100644 --- a/standalone/Dockerfile +++ b/standalone/Dockerfile @@ -95,7 +95,7 @@ RUN addgroup --system tor \ && apt-get update \ && apt-get install -qq --no-install-recommends --no-install-suggests -y \ # image dependencies - tini iproute2 procps vim \ + tini iproute2 procps vim jq \ # servers dependencies (see `install.sh`) build-essential automake pkg-config libtool libltdl-dev python3-dev python3-setuptools python3-pip \ # tor diff --git a/standalone/jam-entrypoint.sh b/standalone/jam-entrypoint.sh index b5692dd..5707ff5 100644 --- a/standalone/jam-entrypoint.sh +++ b/standalone/jam-entrypoint.sh @@ -75,15 +75,32 @@ done # wait for a ready file to be created if necessary if [ "${READY_FILE}" ] && [ "${READY_FILE}" != "false" ]; then - echo "Waiting for $READY_FILE to be created..." + echo "Waiting for file $READY_FILE to be created..." while [ ! -f "$READY_FILE" ]; do sleep 1; done - echo "The chain is fully synched" + echo "Successfully waited for file $READY_FILE to be created." +fi + +btcuser="${jmenv['rpc_user']}:${jmenv['rpc_password']}" +btchost="http://${jmenv['rpc_host']}:${jmenv['rpc_port']}" + +# wait for bitcoind to accept RPC requests if necessary +if [ "${WAIT_FOR_BITCOIND}" = "true" ]; then + echo "Waiting for bitcoind to accept RPC requests..." + getblockchaininfo_payload="{\ + \"jsonrpc\":\"2.0\",\ + \"id\":\"curl\",\ + \"method\":\"getblockchaininfo\",\ + \"params\":{}\ + }" + until curl --silent --user "${btcuser}" --data-binary "${getblockchaininfo_payload}" "${btchost}" | jq -e ".result.blocks >= 100" > /dev/null 2>&1 + do + sleep 5 + done + echo "Successfully waited for bitcoind to accept RPC requests." fi # ensure that a wallet exists and is loaded if necessary if [ "${ENSURE_WALLET}" = "true" ]; then - btcuser="${jmenv['rpc_user']}:${jmenv['rpc_password']}" - btchost="http://${jmenv['rpc_host']}:${jmenv['rpc_port']}" wallet_name="${jmenv['rpc_wallet_file']}" echo "Creating wallet $wallet_name if missing..."