Browse Source

Merge branch 'master' into leftist-flatland

master
BT 4 years ago
committed by GitHub
parent
commit
52c548bd81
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      README.md
  2. 27
      switch.sh

12
README.md

@ -8,16 +8,24 @@
docker pull lncm/neutrino-switcher
```
## If using docker-compose
- Container name of LND needs to match the environment variable defined (if not lnd)
## Files/Folders it needs access to
You may map these anywhere in your filesystem. For best results works best with a similar setup to [this one](https://github.com/lncm/thebox-compose-system)
- /secrets/rpcpass.txt (Bitcoin RPC Password)
- /secrets/rpcpass.txt (Bitcoin RPC Password. Not used if RPCPASS variable is explicitly defined)
- /lnd/lnd.conf (LND configuration. For best results write access please)
- /statuses/ (Write access for notifying of changes to other scripts for now)
- /statuses/ (Write access)
- /var/run/docker.sock (is mapped correctly so it can restart the container)
## Environment Variables
Other than that everything should be in the default paths.
- RPCPASS (default: whatever is set in /secrets/rpcpass.txt .) - If we set this, we do not need to link rpcpass.txt (this is generated by configure-box.sh by [the box configure script](https://github.com/lncm/thebox-compose-system/blob/master/configure-box.sh))
- JSONRPCURL (Default: http://10.254.2.2:8332) : Is the JSON-RPC interface for bitcoind
- LND_CONTAINER_NAME (Default: lnd) : is the container name to restart
- SLEEPTIME (Default: 3600) : Configures how often to poll. Ideally we should set this high so we minimize disruptions, but we might want to set it lower for testing.

27
switch.sh

@ -14,14 +14,27 @@
# Allow access to 'statuses'. /statuses/
# Output: /statuses/node-status-bitcoind-ready (when ready, where a service can pick it up)
# Then
PASSWORD="$(cat /secrets/rpcpass.txt)"
# if RPCPASS doesn't exist then set it (Default to whats in /secrets/rpcpass.txt)
if [ -z $RPCPASS ]; then
RPCPASS="$(cat /secrets/rpcpass.txt)"
fi
# If sleeptime isn't set, set it to 3600 (1 hour)
if [ -z $SLEEPTIME ]; then
SLEEPTIME=3600
fi
# If JSONRPCURL doesn't exist then set it
if [ -z "$JSONRPCURL" ]; then
JSONRPCURL='http://10.254.2.2:8332'
fi
# if LND_CONTAINER_NAME doesn't exist then set it
if [ -z $LND_CONTAINER_NAME ]; then
LND_CONTAINER_NAME="lnd"
fi
PREV_MATCH=
switch_on_sync_done() {
@ -40,7 +53,7 @@ switch_on_sync_done() {
echo 'If set to neutrino then lets check bitcoind'
if ! INFO="$(curl --silent --user "lncm:$PASSWORD" --data-binary '{"jsonrpc": "1.0", "id":"switchme", "method": "getblockchaininfo", "params": [] }' $JSONRPCURL)"; then
if ! INFO="$(curl --silent --user "lncm:$RPCPASS" --data-binary '{"jsonrpc": "1.0", "id":"switchme", "method": "getblockchaininfo", "params": [] }' $JSONRPCURL)"; then
echo "Error: 'getblockchaininfo' request to bitcoind failed"
return
fi
@ -82,6 +95,10 @@ switch_on_sync_done() {
echo 'Bitcoind has been switched across to neutrino'
touch /statuses/node-status-bitcoind-ready
sed -Ei 's|(bitcoin.node)=neutrino|\1=bitcoind|g' /lnd/lnd.conf
echo "Restarting LND"
docker stop $LND_CONTAINER_NAME
docker start $LND_CONTAINER_NAME
}
while true; do
@ -90,6 +107,6 @@ while true; do
break
fi
# Run every every 1 hour
sleep 3600
# Run every every 1 hour by default or as per configurable
sleep $SLEEPTIME
done

Loading…
Cancel
Save