mirror of
https://github.com/rootzoll/raspiblitz.git
synced 2024-11-20 10:12:06 +01:00
#293 reindex detection and script
This commit is contained in:
parent
19f232a982
commit
f7a06d9096
@ -151,6 +151,17 @@ while :
|
||||
continue
|
||||
fi
|
||||
|
||||
# if re-indexing
|
||||
if [ "${state}" = "reindex" ]; then
|
||||
l1="REINDEXING BLOCKCHAIN\n"
|
||||
l2="To monitor & detect finish:\n"
|
||||
l3="ssh admin@${localip}\n"
|
||||
boxwidth=$((${#localip} + 28))
|
||||
dialog --backtitle "RaspiBlitz ${codeVersion} (${state})" --infobox "$l1$l2$l3" 5 ${boxwidth}
|
||||
sleep 3
|
||||
continue
|
||||
fi
|
||||
|
||||
# check if bitcoin is ready
|
||||
sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo 1>/dev/null 2>error.tmp
|
||||
clienterror=`cat error.tmp`
|
||||
|
@ -58,6 +58,13 @@ if [ "${state}" = "recovered" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# signal that a reindex was triggered
|
||||
if [ "${state}" = "reindex" ]; then
|
||||
echo "Re-Index in progress ... start monitoring:"
|
||||
/home/admin/config.scripts/network.reindex.sh
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# if pre-sync is running - stop it - before continue
|
||||
if [ "${state}" = "presync" ]; then
|
||||
# stopping the pre-sync
|
||||
@ -118,6 +125,17 @@ waitUntilChainNetworkIsReady()
|
||||
clienterror=`cat error.tmp`
|
||||
rm error.tmp
|
||||
if [ ${#clienterror} -gt 0 ]; then
|
||||
|
||||
# analyse LOGS for possible reindex
|
||||
reindex=$(sudo cat /mnt/hdd/${network}/debug.log | grep -c 'Please restart with -reindex or -reindex-chainstate to recover')
|
||||
if [ ${reindex} -gt 0 ]; then
|
||||
echo "!! DETECTED NEED FOR RE-INDEX in debug.log ... starting repair script."
|
||||
sleep 3
|
||||
sudo /home/admin/config.scripts/network.reindex.sh
|
||||
exit
|
||||
fi
|
||||
|
||||
# normal info
|
||||
boxwidth=40
|
||||
l1="Waiting for ${network}d to get ready.\n"
|
||||
l2="---> ${clienterror/error*:/}\n"
|
||||
|
66
home.admin/config.scripts/network.reindex.sh
Executable file
66
home.admin/config.scripts/network.reindex.sh
Executable file
@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
|
||||
# command info
|
||||
if [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
|
||||
echo "script to run re-index if the blockchain (in case of repair)"
|
||||
echo "run to start or monitor re-index progress"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# check and load raspiblitz config
|
||||
# to know which network is running
|
||||
source /mnt/hdd/raspiblitz.conf 2>/dev/null
|
||||
if [ ${#network} -eq 0 ]; then
|
||||
echo "FAIL - missing /mnt/hdd/raspiblitz.conf"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# load raspiblitz.info to know if reindex is already running
|
||||
source /home/admin/raspiblitz.info 2>/dev/null
|
||||
if [ ${#state} -eq 0 ]; then
|
||||
echo "FAIL - missing /home/admin/raspiblitz.info"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# if re-index is not running, start ...
|
||||
if [ "${state}" != "reindex" ]; then
|
||||
|
||||
# stop services
|
||||
echo "making sure services are not running .."
|
||||
sudo systemctl stop lnd 2>/dev/null
|
||||
sudo systemctl stop ${network}d 2>/dev/null
|
||||
|
||||
# starting reindex
|
||||
echo "starting re-index ..."
|
||||
sudo -u bitcoin /usr/local/bin/${network}d -daemon -reindex -conf=/home/bitcoin/.${network}/${network}.conf -datadir=/home/bitcoin/.${network}
|
||||
|
||||
# set reindex flag in raspiblitz.info (gets deleted after (final) reboot)
|
||||
sudo sed -i "s/^state=.*/state=reindex/g" /home/admin/raspiblitz.info
|
||||
|
||||
fi
|
||||
|
||||
# while loop to wait to finish
|
||||
finished=0
|
||||
while [ ${finished} -eq 0 ]
|
||||
do
|
||||
clear
|
||||
echo "*************************"
|
||||
echo "REINDEXING BLOCKCHAIN"
|
||||
echo "*************************"
|
||||
echo "THIS CAN TAKE SOME LONG TIME"
|
||||
echo "If you dont see any progress after 24h press X to stop."
|
||||
|
||||
#TODO: detect and display progress
|
||||
#TODO: determine when finished and then finished=1
|
||||
|
||||
done
|
||||
|
||||
# trigger reboot when finished
|
||||
echo "*************************"
|
||||
echo "Re-Index finished"
|
||||
echo "Starting reboot ..."
|
||||
echo "*************************"
|
||||
# clean logs (to prevent a false reindex detection)
|
||||
sudo rm /mnt/hdd/${network}/debug.log
|
||||
# reboot
|
||||
sudo shutdown -r now
|
Loading…
Reference in New Issue
Block a user