Refactor BTCPay install

This commit is contained in:
Taylor Helsper 2022-04-13 21:36:04 -05:00
parent d40a816892
commit 6a885f6cbd
13 changed files with 108 additions and 207 deletions

View File

@ -3,18 +3,21 @@
[Unit]
Description=BTCPayServer service
After=docker.service network-online.target bitcoin.service lnd.service
Requires=docker.service network-online.target bitcoin.service lnd.service
After=docker.service network-online.target bitcoin.service
Requires=docker.service network-online.target bitcoin.service
[Service]
Type=oneshot
RemainAfterExit=yes
# myNode Customizations
ExecStartPre=/usr/bin/is_not_shutting_down.sh
ExecStartPre=/usr/bin/is_mainnet.sh
ExecStartPre=/usr/bin/wait_on_lnd.sh
ExecStart=/bin/bash -c '. "/opt/mynode/btcpayserver/btcpay-env.sh" && cd "$BTCPAY_BASE_DIRECTORY" && . helpers.sh && btcpay_up'
ExecStop=/bin/bash -c '. "/opt/mynode/btcpayserver/btcpay-env.sh" && cd "$BTCPAY_BASE_DIRECTORY" && . helpers.sh && btcpay_down'
ExecReload=/bin/bash -c '. "/opt/mynode/btcpayserver/btcpay-env.sh" && cd "$BTCPAY_BASE_DIRECTORY" && . helpers.sh && btcpay_restart'
ExecStartPre=/usr/bin/wait_on_docker_image_install.sh
ExecStart=/bin/bash -c '. "/etc/profile.d/btcpay-env.sh" && cd "$BTCPAY_BASE_DIRECTORY/btcpayserver-docker" && . helpers.sh && btcpay_up'
ExecStop=/bin/bash -c '. "/etc/profile.d/btcpay-env.sh" && cd "$BTCPAY_BASE_DIRECTORY/btcpayserver-docker" && . helpers.sh && btcpay_down'
ExecReload=/bin/bash -c '. "/etc/profile.d/btcpay-env.sh" && cd "$BTCPAY_BASE_DIRECTORY/btcpayserver-docker" && . helpers.sh && btcpay_restart'
[Install]
WantedBy=multi-user.target

View File

@ -128,13 +128,51 @@ while true; do
touch /tmp/need_application_refresh
# Upgrade BTCPay Server (docker compose does install, just need version file update)
# Upgrade BTCPay Server
if should_install_app "btcpayserver" ; then
CURRENT=""
if [ -f $BTCPAYSERVER_VERSION_FILE ]; then
CURRENT=$(cat $BTCPAYSERVER_VERSION_FILE)
fi
if [ "$CURRENT" != "$BTCPAYSERVER_VERSION" ]; then
# Create a folder for BTCPay
rm -rf sudo /mnt/hdd/mynode/btcpayserver
mkdir -p /mnt/hdd/mynode/btcpayserver
cd /mnt/hdd/mynode/btcpayserver
# Clone this repository
#git clone https://github.com/btcpayserver/btcpayserver-docker
git clone https://github.com/tehelsper/btcpayserver-docker.git
cd btcpayserver-docker
# Run btcpay-setup.sh with the right parameters
export BTCPAY_HOST="mynode.local"
export NBITCOIN_NETWORK="mainnet"
export BTCPAYGEN_CRYPTO1="btc"
export BTCPAYGEN_ADDITIONAL_FRAGMENTS="btcpayserver-noreverseproxy;bitcoin.custom;lnd.custom"
export BTCPAYGEN_EXCLUDE_FRAGMENTS="opt-add-tor;bitcoin;bitcoin-lnd;"
export BTCPAYGEN_REVERSEPROXY="none"
export NOREVERSEPROXY_HTTP_PORT=49392
export REVERSEPROXY_HTTP_PORT=49392
export REMOTE_BTC_RPC_USERNAME="mynode"
BTCRPCPW=$(cat /mnt/hdd/mynode/settings/.btcrpcpw)
export REMOTE_BTC_RPC_PASSWORD="$BTCRPCPW"
export BTCPAYGEN_LIGHTNING="lnd"
export BTCPAY_ENABLE_SSH=false
export BTCPAY_IMAGE=btcpayserver/btcpayserver:$BTCPAYSERVER_VERSION
cp -f /usr/share/btcpayserver/bitcoin.custom.yml /mnt/hdd/mynode/btcpayserver/btcpayserver-docker/docker-compose-generator/docker-fragments/bitcoin.custom.yml
cp -f /usr/share/btcpayserver/lnd.custom.yml /mnt/hdd/mynode/btcpayserver/btcpayserver-docker/docker-compose-generator/docker-fragments/lnd.custom.yml
rm -rf /usr/local/bin/btcpay-*
rm -rf /usr/local/bin/changedomain.sh
#. ./btcpay-setup.sh # Install and run
bash -c ". ./btcpay-setup.sh --install-only --no-startup-register --no-systemd-reload"
systemctl enable btcpayserver
systemctl restart btcpayserver
echo $BTCPAYSERVER_VERSION > $BTCPAYSERVER_VERSION_FILE
fi
fi

View File

@ -34,12 +34,17 @@ elif [ "$APP" = "netdata" ]; then
systemctl stop netdata
docker rmi netdata/netdata || true
elif [ "$APP" = "btcpayserver" ]; then
cp /usr/share/btcpayserver/env /opt/mynode/btcpayserver/.env
cp /usr/share/btcpayserver/btcpay-env.sh /opt/mynode/btcpayserver/
cp /usr/share/btcpayserver/docker-compose.generated.yml /opt/mynode/btcpayserver/
cp /usr/share/btcpayserver/helpers.sh /opt/mynode/btcpayserver/
. "/opt/mynode/btcpayserver/btcpay-env.sh" && cd "$BTCPAY_BASE_DIRECTORY" && . helpers.sh && btcpay_remove
cd ~
# Stop and clean images
/usr/local/bin/btcpay-down.sh
/usr/local/bin/btcpay-clean.sh
# Remove files and data (don't remove volume for re-install)
rm -f /etc/profile.d/btcpay-env.sh
rm -rf /usr/local/bin/btcpay-*
rm -rf /usr/local/bin/changedomain.sh
# Finally remove main folder
rm -rf /mnt/hdd/mynode/btcpayserver
elif [ "$APP" = "tor" ]; then
apt-get remove -y tor
apt-get install -y tor

View File

@ -388,16 +388,7 @@ fi
# Moved to pre_rtl.sh
# BTCPay Server Setup
mkdir -p /opt/mynode/btcpayserver
cp -n /usr/share/btcpayserver/env /opt/mynode/btcpayserver/.env
cp -n /usr/share/btcpayserver/btcpay-env.sh /opt/mynode/btcpayserver/
cp -n /usr/share/btcpayserver/docker-compose.generated.yml /opt/mynode/btcpayserver/
cp -n /usr/share/btcpayserver/helpers.sh /opt/mynode/btcpayserver/
if [ -f /opt/mynode/btcpayserver/.env ]; then
sed -i "s/BTCPAY_VERSION=.*/BTCPAY_VERSION=$BTCPAYSERVER_VERSION/g" /opt/mynode/btcpayserver/.env || true
sed -i "s/NBXPLORER_VERSION.*/NBXPLORER_VERSION=$BTCPAYSERVER_NBXPLORER_VERSION/g" /opt/mynode/btcpayserver/.env || true
sed -i "s/POSTGRES_VERSION.*/POSTGRES_VERSION=$BTCPAYSERVER_POSTGRES_VERSION/g" /opt/mynode/btcpayserver/.env || true
fi
# Now in mynode_docker_images.sh (any new setup should go into pre_btcpayserver.sh)
# LNBits Config
if [ -d /opt/mynode/lnbits ]; then

View File

@ -25,12 +25,20 @@ sync
if [ "$APP" = "bos" ]; then
npm uninstall -g balanceofsatoshis
elif [ "$APP" = "btcpayserver" ]; then
cp /usr/share/btcpayserver/env /opt/mynode/btcpayserver/.env
cp /usr/share/btcpayserver/btcpay-env.sh /opt/mynode/btcpayserver/
cp /usr/share/btcpayserver/docker-compose.generated.yml /opt/mynode/btcpayserver/
cp /usr/share/btcpayserver/helpers.sh /opt/mynode/btcpayserver/
. "/opt/mynode/btcpayserver/btcpay-env.sh" && cd "$BTCPAY_BASE_DIRECTORY" && . helpers.sh && btcpay_remove
# Stop and clean images
/usr/local/bin/btcpay-down.sh
/usr/local/bin/btcpay-clean.sh
# Remove files and data
cd "$(dirname "$BTCPAY_ENV_FILE")"
docker-compose -f $BTCPAY_DOCKER_COMPOSE down --v # Remove volumes (uninstall only, not reinstall)
cd ~
rm -f /etc/profile.d/btcpay-env.sh
rm -rf /usr/local/bin/btcpay-*
rm -rf /usr/local/bin/changedomain.sh
# Finally remove main folder
rm -rf /mnt/hdd/mynode/btcpayserver
elif [ "$APP" = "btcrpcexplorer" ]; then
rm -rf /opt/mynode/btc-rpc-explorer
elif [ "$APP" = "dojo" ]; then

View File

@ -0,0 +1,18 @@
version: "3"
services:
btcpayserver:
environment:
BTCPAY_CHAINS: "btc"
BTCPAY_BTCEXPLORERURL: http://nbxplorer:32838/
nbxplorer:
environment:
NBXPLORER_CHAINS: "btc"
NBXPLORER_BTCRPCURL: http://host.docker.internal:8332/
NBXPLORER_BTCRPCUSER: "${REMOTE_BTC_RPC_USERNAME}"
NBXPLORER_BTCRPCPASSWORD: "${REMOTE_BTC_RPC_PASSWORD}"
NBXPLORER_BTCNODEENDPOINT: host.docker.internal:8333
volumes:
- "/mnt/hdd/mynode/bitcoin:/root/.bitcoin"
extra_hosts:
- "host.docker.internal:172.17.0.1"

View File

@ -1,26 +0,0 @@
#!/bin/bash
export COMPOSE_HTTP_TIMEOUT="300"
export BTCPAYGEN_OLD_PREGEN="false"
export BTCPAYGEN_CRYPTO1="btc"
export BTCPAYGEN_CRYPTO2=""
export BTCPAYGEN_CRYPTO3=""
export BTCPAYGEN_CRYPTO4=""
export BTCPAYGEN_CRYPTO5=""
export BTCPAYGEN_CRYPTO6=""
export BTCPAYGEN_CRYPTO7=""
export BTCPAYGEN_CRYPTO8=""
export BTCPAYGEN_CRYPTO9=""
export BTCPAYGEN_LIGHTNING="lnd"
export BTCPAYGEN_REVERSEPROXY="nginx"
export BTCPAYGEN_ADDITIONAL_FRAGMENTS=""
export BTCPAYGEN_EXCLUDE_FRAGMENTS="opt-add-tor"
export BTCPAY_DOCKER_COMPOSE="/opt/mynode/btcpayserver/docker-compose.generated.yml"
export BTCPAY_BASE_DIRECTORY="/opt/mynode/btcpayserver"
export BTCPAY_ENV_FILE="/opt/mynode/btcpayserver/.env"
export BTCPAY_HOST_SSHKEYFILE=""
export BTCPAY_ENABLE_SSH=true
if cat "$BTCPAY_ENV_FILE" &> /dev/null; then
while IFS= read -r line; do
! [[ "$line" == "#"* ]] && [[ "$line" == *"="* ]] && export "$line"
done < "$BTCPAY_ENV_FILE"
fi

View File

@ -1,72 +0,0 @@
version: "3"
services:
btcpayserver:
restart: unless-stopped
image: btcpayserver/btcpayserver:${BTCPAY_VERSION}
network_mode: host
# expose:
# - "49392"
environment:
BTCPAY_POSTGRES: User ID=postgres;Host=localhost;Port=5432;Database=btcpayserver${NBITCOIN_NETWORK:-regtest}
BTCPAY_NETWORK: ${NBITCOIN_NETWORK:-regtest}
BTCPAY_BIND: 0.0.0.0:49392
BTCPAY_ROOTPATH: ${BTCPAY_ROOTPATH:-/}
BTCPAY_SSHCONNECTION: "root@localhost"
BTCPAY_SSHTRUSTEDFINGERPRINTS: ${BTCPAY_SSHTRUSTEDFINGERPRINTS}
BTCPAY_SSHKEYFILE: ${BTCPAY_SSHKEYFILE}
BTCPAY_SSHAUTHORIZEDKEYS: ${BTCPAY_SSHAUTHORIZEDKEYS}
BTCPAY_DEBUGLOG: btcpay.log
BTCPAY_DOCKERDEPLOYMENT: "true"
BTCPAY_CHAINS: "btc"
BTCPAY_BTCEXPLORERURL: http://localhost:32838/
BTCPAY_BTCLIGHTNING: "type=lnd-rest;server=https://localhost:10080/;macaroonfilepath=/etc/lnd_bitcoin/data/chain/bitcoin/mainnet/admin.macaroon;allowinsecure=true"
BTCPAY_BTCEXTERNALRTL: "server=/rtl/api/authenticate/cookie;cookiefile=/etc/lnd_bitcoin_rtl/.cookie"
BTCPAY_BTCEXTERNALLNDGRPC: "server=/;macaroonfilepath=/etc/lnd_bitcoin/data/chain/bitcoin/mainnet/admin.macaroon;macaroondirectorypath=/etc/lnd_bitcoin/data/chain/bitcoin/mainnet/"
BTCPAY_BTCEXTERNALLNDREST: "server=/lnd-rest/btc/;macaroonfilepath=/etc/lnd_bitcoin/data/chain/bitcoin/mainnet/admin.macaroon;macaroondirectorypath=/etc/lnd_bitcoin/data/chain/bitcoin/mainnet"
BTCPAY_BTCEXTERNALLNDSEEDBACKUP: "/etc/lnd_bitcoin/data/chain/bitcoin/${NBITCOIN_NETWORK:-regtest}/walletunlock.json"
VIRTUAL_NETWORK: nginx-proxy
VIRTUAL_PORT: 49392
VIRTUAL_HOST: ${BTCPAY_HOST},${BTCPAY_ADDITIONAL_HOSTS}
VIRTUAL_HOST_NAME: "btcpay"
SSL_POLICY: Mozilla-Modern
LETSENCRYPT_HOST: ${BTCPAY_HOST},${BTCPAY_ADDITIONAL_HOSTS}
LETSENCRYPT_EMAIL: ${LETSENCRYPT_EMAIL:-<no value>}
volumes:
- "btcpay_datadir:/datadir"
- "nbxplorer_datadir:/root/.nbxplorer"
- "/mnt/hdd/mynode/lnd:/etc/lnd_bitcoin"
- "/root/.ssh/authorized_keys:${BTCPAY_SSHAUTHORIZEDKEYS}"
- "/root/.ssh/id_rsa_btcpay:${BTCPAY_SSHKEYFILE}"
- "btcpay_pluginsdir:/root/.btcpayserver/Plugins"
nbxplorer:
restart: unless-stopped
image: nicolasdorier/nbxplorer:${NBXPLORER_VERSION}
network_mode: host
# expose:
# - "32838"
environment:
NBXPLORER_NETWORK: ${NBITCOIN_NETWORK:-regtest}
NBXPLORER_BIND: 0.0.0.0:32838
NBXPLORER_TRIMEVENTS: 10000
NBXPLORER_SIGNALFILESDIR: /datadir
NBXPLORER_CHAINS: "btc"
NBXPLORER_BTCRPCURL: http://localhost:8332/
NBXPLORER_BTCNODEENDPOINT: localhost:8333
volumes:
- "nbxplorer_datadir:/datadir"
postgres:
restart: unless-stopped
image: btcpayserver/postgres:${POSTGRES_VERSION}
network_mode: host
environment:
POSTGRES_HOST_AUTH_METHOD: trust
volumes:
- "postgres_datadir:/var/lib/postgresql/data"
volumes:
btcpay_datadir:
btcpay_pluginsdir:
postgres_datadir:
nbxplorer_datadir:
networks: {}

View File

@ -1,27 +0,0 @@
BTCPAY_PROTOCOL=https
BTCPAY_HOST=mynode.local
BTCPAY_ADDITIONAL_HOSTS=btcpay-mynode.local
BTCPAY_ANNOUNCEABLE_HOST=
REVERSEPROXY_HTTP_PORT=80
REVERSEPROXY_HTTPS_PORT=443
REVERSEPROXY_DEFAULT_HOST=none
BTCPAY_IMAGE=
ACME_CA_URI=production
NBITCOIN_NETWORK=mainnet
LETSENCRYPT_EMAIL=
LIGHTNING_ALIAS=
BTCPAY_SSHTRUSTEDFINGERPRINTS=
BTCPAY_SSHKEYFILE=/datadir/host_id_rsa
BTCPAY_SSHAUTHORIZEDKEYS=/datadir/host_authorized_keys
BTCPAY_HOST_SSHAUTHORIZEDKEYS=/root/.ssh/authorized_keys
LIBREPATRON_HOST=
BTCTRANSMUTER_HOST=
BTCPAY_CRYPTOS=btc
WOOCOMMERCE_HOST=
TOR_RELAY_NICKNAME=
TOR_RELAY_EMAIL=
# myNode Additions
BTCPAY_VERSION=REPLACE_BTCPAY_VERSION
NBXPLORER_VERSION=REPLACE_NBXPLORER_VERSION
POSTGRES_VERSION=REPLACE_POSTGRES_VERSION

View File

@ -1,50 +0,0 @@
btcpay_up() {
pushd . > /dev/null
cd "$(dirname "$BTCPAY_ENV_FILE")"
docker-compose -f $BTCPAY_DOCKER_COMPOSE up --remove-orphans -d -t "${COMPOSE_HTTP_TIMEOUT:-180}"
# Depending on docker-compose, either the timeout does not work, or "compose -d and --timeout cannot be combined"
if ! [ $? -eq 0 ]; then
docker-compose -f $BTCPAY_DOCKER_COMPOSE up --remove-orphans -d
fi
popd > /dev/null
}
btcpay_pull() {
pushd . > /dev/null
cd "$(dirname "$BTCPAY_ENV_FILE")"
docker-compose -f "$BTCPAY_DOCKER_COMPOSE" pull
popd > /dev/null
}
btcpay_down() {
pushd . > /dev/null
cd "$(dirname "$BTCPAY_ENV_FILE")"
docker-compose -f $BTCPAY_DOCKER_COMPOSE down -t "${COMPOSE_HTTP_TIMEOUT:-180}"
# Depending on docker-compose, the timeout does not work.
if ! [ $? -eq 0 ]; then
docker-compose -f $BTCPAY_DOCKER_COMPOSE down
fi
popd > /dev/null
}
btcpay_restart() {
pushd . > /dev/null
cd "$(dirname "$BTCPAY_ENV_FILE")"
docker-compose -f $BTCPAY_DOCKER_COMPOSE restart -t "${COMPOSE_HTTP_TIMEOUT:-180}"
# Depending on docker-compose, the timeout does not work.
if ! [ $? -eq 0 ]; then
docker-compose -f $BTCPAY_DOCKER_COMPOSE restart
fi
popd > /dev/null
}
btcpay_remove() {
pushd . > /dev/null
cd "$(dirname "$BTCPAY_ENV_FILE")"
docker-compose -f $BTCPAY_DOCKER_COMPOSE down -v -t "${COMPOSE_HTTP_TIMEOUT:-180}"
# Depending on docker-compose, the timeout does not work.
if ! [ $? -eq 0 ]; then
docker-compose -f $BTCPAY_DOCKER_COMPOSE -v down
fi
popd > /dev/null
}

View File

@ -0,0 +1,13 @@
version: "3"
services:
btcpayserver:
environment:
BTCPAY_BTCLIGHTNING: "type=lnd-rest;server=http://host.docker.internal:8080/;macaroonfilepath=/etc/lnd_bitcoin/admin.macaroon;allowinsecure=true"
BTCPAY_BTCEXTERNALLNDGRPC: "server=/;macaroonfilepath=/etc/lnd_bitcoin/admin.macaroon;macaroondirectorypath=/etc/lnd_bitcoin"
BTCPAY_BTCEXTERNALLNDREST: "server=/lnd-rest/btc/;macaroonfilepath=/etc/lnd_bitcoin/admin.macaroon;macaroondirectorypath=/etc/lnd_bitcoin"
BTCPAY_BTCEXTERNALLNDSEEDBACKUP: "/etc/lnd_bitcoin/data/chain/bitcoin/${NBITCOIN_NETWORK:-regtest}/walletunlock.json"
volumes:
- "/mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet:/etc/lnd_bitcoin"
extra_hosts:
- "host.docker.internal:172.17.0.1"

View File

@ -77,7 +77,7 @@ RTL_VERSION="v0.12.2"
RTL_VERSION_FILE=/home/bitcoin/.mynode/rtl_version
RTL_LATEST_VERSION_FILE=/home/bitcoin/.mynode/rtl_version_latest
BTCPAYSERVER_VERSION="1.4.9"
BTCPAYSERVER_VERSION="1.4.8"
BTCPAYSERVER_NBXPLORER_VERSION="2.2.20"
BTCPAYSERVER_POSTGRES_VERSION="13.6"
BTCPAYSERVER_VERSION_FILE=/home/bitcoin/.mynode/btcpayserver_version

View File

@ -287,9 +287,9 @@
{{ btcpayserver_status }}
<span class='status_container_list'>
Running Containers:
{% if 'btcpayserver_btcpayserver_1' in running_containers %} btcpayserver {% endif %}
{% if 'btcpayserver_nbxplorer_1' in running_containers %} nbxplorer {% endif %}
{% if 'btcpayserver_postgres_1' in running_containers %} postgres {% endif %}
{% if 'generated_btcpayserver_1' in running_containers %} btcpayserver {% endif %}
{% if 'generated_nbxplorer_1' in running_containers %} nbxplorer {% endif %}
{% if 'generated_postgres_1' in running_containers %} postgres {% endif %}
</span>
</div>
<button id="show_btcpayserver_status" onclick="showLog('btcpayserver')" class="ui-button ui-widget ui-corner-all settings_button_small">Show Log</button>