Skip to content

Commit

Permalink
Docker: Don't start bitcoind when using an external lightningd instance
Browse files Browse the repository at this point in the history
Closes #31.
  • Loading branch information
shesek committed Apr 11, 2018
1 parent 705cdac commit 0c6c67f
Showing 1 changed file with 33 additions and 31 deletions.
64 changes: 33 additions & 31 deletions bin/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,51 @@ trap 'kill `jobs -p`' SIGTERM

[[ "$NETWORK" == "mainnet" ]] && NETWORK=bitcoin

if [ -d /etc/bitcoin ]; then
echo -n "Connecting to bitcoind configured in /etc/bitcoin... "
if [ -d /etc/lightning ]; then
echo -n "Using lightningd directory mounted in /etc/lightning... "
LN_PATH=/etc/lightning

RPC_OPT="-datadir=/etc/bitcoin $([[ -z "$BITCOIND_RPCCONNECT" ]] || echo "-rpcconnect=$BITCOIND_RPCCONNECT")"
else

elif [ -n "$BITCOIND_URI" ]; then
[[ "$BITCOIND_URI" =~ ^[a-z]+:\/+(([^:/]+):([^@/]+))@([^:/]+:[0-9]+)/?$ ]] || \
{ echo >&2 "ERROR: invalid bitcoind URI: $BITCOIND_URI"; exit 1; }
# Setup bitcoind (only needed when we're starting our own lightningd instance)
if [ -d /etc/bitcoin ]; then
echo -n "Connecting to bitcoind configured in /etc/bitcoin... "

echo -n "Connecting to bitcoind at ${BASH_REMATCH[4]}... "
RPC_OPT="-datadir=/etc/bitcoin $([[ -z "$BITCOIND_RPCCONNECT" ]] || echo "-rpcconnect=$BITCOIND_RPCCONNECT")"

RPC_OPT="-rpcconnect=${BASH_REMATCH[4]}"
elif [ -n "$BITCOIND_URI" ]; then
[[ "$BITCOIND_URI" =~ ^[a-z]+:\/+(([^:/]+):([^@/]+))@([^:/]+:[0-9]+)/?$ ]] || \
{ echo >&2 "ERROR: invalid bitcoind URI: $BITCOIND_URI"; exit 1; }

if [ "${BASH_REMATCH[2]}" != "__cookie__" ]; then
RPC_OPT="$RPC_OPT -rpcuser=${BASH_REMATCH[2]} -rpcpassword=${BASH_REMATCH[3]}"
else
RPC_OPT="$RPC_OPT -datadir=/tmp/bitcoin"
[[ "$NETWORK" == "bitcoin" ]] && NET_PATH=/tmp/bitcoin || NET_PATH=/tmp/bitcoin/$NETWORK
mkdir -p $NET_PATH
echo "${BASH_REMATCH[1]}" > $NET_PATH/.cookie
fi
echo -n "Connecting to bitcoind at ${BASH_REMATCH[4]}... "

else
echo -n "Starting bitcoind... "
RPC_OPT="-rpcconnect=${BASH_REMATCH[4]}"

mkdir -p /data/bitcoin
RPC_OPT="-datadir=/data/bitcoin"
if [ "${BASH_REMATCH[2]}" != "__cookie__" ]; then
RPC_OPT="$RPC_OPT -rpcuser=${BASH_REMATCH[2]} -rpcpassword=${BASH_REMATCH[3]}"
else
RPC_OPT="$RPC_OPT -datadir=/tmp/bitcoin"
[[ "$NETWORK" == "bitcoin" ]] && NET_PATH=/tmp/bitcoin || NET_PATH=/tmp/bitcoin/$NETWORK
mkdir -p $NET_PATH
echo "${BASH_REMATCH[1]}" > $NET_PATH/.cookie
fi

bitcoind -$NETWORK $RPC_OPT $BITCOIND_OPTS &
echo -n "waiting for cookie... "
sed --quiet '/^\.cookie$/ q' <(inotifywait -e create,moved_to --format '%f' -qmr /data/bitcoin)
fi
else
echo -n "Starting bitcoind... "

echo -n "waiting for RPC... "
bitcoin-cli -$NETWORK $RPC_OPT -rpcwait getblockchaininfo > /dev/null
echo "ready."
mkdir -p /data/bitcoin
RPC_OPT="-datadir=/data/bitcoin"

bitcoind -$NETWORK $RPC_OPT $BITCOIND_OPTS &
echo -n "waiting for cookie... "
sed --quiet '/^\.cookie$/ q' <(inotifywait -e create,moved_to --format '%f' -qmr /data/bitcoin)
fi

if [ -d /etc/lightning ]; then
echo -n "Using lightningd directory mounted in /etc/lightning... "
LN_PATH=/etc/lightning
echo -n "waiting for RPC... "
bitcoin-cli -$NETWORK $RPC_OPT -rpcwait getblockchaininfo > /dev/null
echo "ready."

else
# Setup lightning
echo -n "Starting lightningd... "

LN_PATH=/data/lightning
Expand Down

0 comments on commit 0c6c67f

Please sign in to comment.