diff --git a/rootfs/standard/etc/systemd/system/btc_rpc_explorer.service b/rootfs/standard/etc/systemd/system/btc_rpc_explorer.service index 5d1b080c..f1241379 100644 --- a/rootfs/standard/etc/systemd/system/btc_rpc_explorer.service +++ b/rootfs/standard/etc/systemd/system/btc_rpc_explorer.service @@ -8,6 +8,7 @@ After=bitcoind.service [Service] ExecStartPre=/usr/bin/wait_on_bitcoin.sh +ExecStartPre=/usr/bin/wait_on_electrs.sh WorkingDirectory=/opt/mynode/btc-rpc-explorer ExecStart=/usr/bin/npm start diff --git a/rootfs/standard/usr/bin/wait_on_electrs.sh b/rootfs/standard/usr/bin/wait_on_electrs.sh new file mode 100755 index 00000000..3e8f1097 --- /dev/null +++ b/rootfs/standard/usr/bin/wait_on_electrs.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -x +set -e + +# Wait to see if bitcoind is synced +echo "Checking if electrum server is ready is synced..." +while [ ! -f "/tmp/electrs_up_to_date" ]; do + echo "electrs not synced, sleeping 1m" + /bin/sleep 30s +done + +exit 0 \ No newline at end of file diff --git a/rootfs/standard/var/www/mynode/electrum_info.py b/rootfs/standard/var/www/mynode/electrum_info.py index 307c2c47..6e22efca 100644 --- a/rootfs/standard/var/www/mynode/electrum_info.py +++ b/rootfs/standard/var/www/mynode/electrum_info.py @@ -4,6 +4,7 @@ import subprocess import requests import socket import json +import os electrum_server_current_block = None @@ -15,6 +16,7 @@ def get_electrum_server_current_block(): def update_electrs_info(): global electrum_server_current_block + global electrs_active try: raw_data = requests.get("http://localhost:4224") @@ -23,6 +25,12 @@ def update_electrs_info(): for sample in family.samples: if sample.name == "electrs_index_height": electrum_server_current_block = int(sample.value) + + bitcoin_block_height = get_bitcoin_block_height() + if electrum_server_current_block != None and bitcoin_block_height != None: + if electrum_server_current_block > bitcoin_block_height - 2: + os.system("touch /tmp/electrs_up_to_date") + electrs_active = True except: pass diff --git a/rootfs/standard/var/www/mynode/mynode.py b/rootfs/standard/var/www/mynode/mynode.py index da92f4e1..e1068d64 100644 --- a/rootfs/standard/var/www/mynode/mynode.py +++ b/rootfs/standard/var/www/mynode/mynode.py @@ -299,11 +299,16 @@ def index(): # Find btc-rpc-explorer status btcrpcexplorer_status = "BTC RPC Explorer" if is_btcrpcexplorer_enabled(): - status = os.system("systemctl status btc_rpc_explorer --no-pager") - if status != 0: - btcrpcexplorer_status_color = "red" + if is_electrs_active(): + status = os.system("systemctl status btc_rpc_explorer --no-pager") + if status != 0: + btcrpcexplorer_status_color = "red" + else: + btcrpcexplorer_status_color = "green" + btcrpcexplorer_ready = True else: btcrpcexplorer_status_color = "green" + btcrpcexplorer_status = "Waiting on electrs..." # Find explorer status explorer_status_color = electrs_status_color diff --git a/rootfs/standard/var/www/mynode/templates/includes/apps_standard.html b/rootfs/standard/var/www/mynode/templates/includes/apps_standard.html index 452f52be..dd916b07 100644 --- a/rootfs/standard/var/www/mynode/templates/includes/apps_standard.html +++ b/rootfs/standard/var/www/mynode/templates/includes/apps_standard.html @@ -59,9 +59,13 @@
{{ btcrpcexplorer_status }}
{% if btcrpcexplorer_enabled %} - Explorer + {% if btcrpcexplorer_ready %} + Explorer + Disable + {% endif %} + {% else %} + Enable {% endif %} - {% if btcrpcexplorer_enabled %}Disable{% else %}Enable{% endif %}