From 3ec220e8b14e48a1046edbe819bef3919f9fca75 Mon Sep 17 00:00:00 2001 From: openoms Date: Fri, 25 Oct 2024 22:32:12 +0200 Subject: [PATCH] btc-rpc-explorer: check for electrs and fulcrum --- .../config.scripts/bonus.btc-rpc-explorer.sh | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/home.admin/config.scripts/bonus.btc-rpc-explorer.sh b/home.admin/config.scripts/bonus.btc-rpc-explorer.sh index 9d6f6283b..1790fa616 100755 --- a/home.admin/config.scripts/bonus.btc-rpc-explorer.sh +++ b/home.admin/config.scripts/bonus.btc-rpc-explorer.sh @@ -147,26 +147,36 @@ if [ "$1" = "prestart" ]; then # check if electrs is installed & running if [ "${ElectRS}" == "on" ]; then - # CHECK THAT ELECTRS INDEX IS BUILD (WAITLOOP) - # electrs listening in port 50001 means index is build + # CHECK THAT ELECTRS INDEX IS BUILT (WAITLOOP) + # electrs listening in port 50001 means index is built # Use flags: t = tcp protocol only / a = list all connection states (includes LISTEN) / n = don't resolve names => no dns spam - isElectrumReady=$(netstat -tan | grep -c "50001") - if [ "${isElectrumReady}" == "0" ]; then - echo "# electrs is ON but not ready .. might still building index - kick systemd service into fail/wait/restart" - exit 1 - fi + isElectrsReady=$(netstat -tan | grep -c "50001") echo "# electrs is ON .. and ready (${isElectrumReady})" + electrumTCPport=50001 + fi - # CHECK THAT ELECTRS IS PART OF CONFIG + # check if fulcrum is installed & running + if [ "${fulcrum}" == "on" ]; then + isFulcrumReady=$(netstat -tan | grep -c "50021") + echo "# fulcrum is ON .. and ready (${isElectrumReady})" + electrumTCPport=50021 + fi + + # Exit only if either service is on but neither is ready + if { [ "${ElectRS}" == "on" ] && [ "${electrsReady}" == "0" ]; } || { [ "${fulcrum}" == "on" ] && [ "${fulcrumReady}" == "0" ]; }; then + echo "# An Electrum Server is ON but not ready .. might still building index - kick systemd service into fail/wait/restart" + exit 1 + fi + + if [ ${isElectrsReady} -gt 0 ] || [ ${isFulcrumReady} -gt 0 ]; then + # CHECK THAT ELECTRUM SERVER IS PART OF CONFIG echo "# updating BTCEXP_ADDRESS_API=electrumx" sed -i 's/^BTCEXP_ADDRESS_API=.*/BTCEXP_ADDRESS_API=electrumx/g' /home/btcrpcexplorer/.config/btc-rpc-explorer.env - + sed -i "s/^BTCEXP_ELECTRUMX_SERVERS=.*/BTCEXP_ELECTRUMX_SERVERS=tcp://127.0.0.1:${electrumTCPport}/g" /home/btcrpcexplorer/.config/btc-rpc-explorer.env else - # ELECTRS=OFF --> MAKE SURE IT IS NOT CONNECTED echo "# updating BTCEXP_ADDRESS_API=none" sed -i 's/^BTCEXP_ADDRESS_API=.*/BTCEXP_ADDRESS_API=none/g' /home/btcrpcexplorer/.config/btc-rpc-explorer.env - fi # UPDATE RPC PASSWORD