raspiblitz/home.admin/config.scripts/blitz.statusscan.sh

188 lines
5.9 KiB
Bash
Raw Normal View History

2019-04-16 21:25:27 +01:00
#!/bin/bash
source /home/admin/raspiblitz.info
source /mnt/hdd/raspiblitz.conf
# command info
if [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "# script to scan the state of the system after setup"
exit 1
fi
# measure time of scan
startTime=$(date +%s)
2019-04-16 21:31:52 +01:00
# macke sure temp folder on HDD is available and fro all usable
sudo mkdir /mnt/hdd/temp 2>/dev/null
sudo chmod 777 -R /mnt/hdd/temp 2>/dev/null
2019-04-16 21:25:27 +01:00
# localIP
localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
echo "localIP='${localip}'"
2019-04-16 22:00:49 +01:00
# temp
tempC=$(echo "scale=1; $(cat /sys/class/thermal/thermal_zone0/temp)/1000" | bc)
echo "tempCelsius='${tempC}'"
2019-04-16 23:34:53 +01:00
# uptime in seconds
uptime=$(awk '{printf("%d\n",$1 + 0.5)}' /proc/uptime)
echo "uptime=${uptime}"
2019-04-24 13:47:58 +02:00
# count restarts of bitcoind/litecoind
2019-04-24 16:23:15 +02:00
startcountBlockchain=$(cat systemd.blockchain.log 2>/dev/null | grep -c "STARTED")
2019-04-24 13:47:58 +02:00
echo "startcountBlockchain=${startcountBlockchain}"
2019-04-16 21:25:27 +01:00
# is bitcoind running
bitcoinRunning=$(systemctl status ${network}d.service 2>/dev/null | grep -c running)
echo "bitcoinActive=${bitcoinRunning}"
if [ ${bitcoinRunning} -eq 1 ]; then
# get blockchain info
2019-04-17 00:17:25 +01:00
sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo 1>/mnt/hdd/temp/.bitcoind.out 2>/mnt/hdd/temp/.bitcoind.error
2019-04-16 21:25:27 +01:00
# check if error on request
2019-04-17 00:17:25 +01:00
blockchaininfo=$(cat /mnt/hdd/temp/.bitcoind.out 2>/dev/null)
2019-04-17 00:03:36 +01:00
bitcoinError=$(cat /mnt/hdd/temp/.bitcoind.error 2>/dev/null)
2019-04-24 23:56:43 +02:00
#rm /mnt/hdd/temp/.bitcoind.error 2>/dev/null
2019-04-16 21:26:37 +01:00
if [ ${#bitcoinError} -gt 0 ]; then
2019-04-17 00:26:30 +01:00
bitcoinErrorShort=$(echo ${bitcoinError/error*:/} | sed 's/[^a-zA-Z0-9 ]//g')
echo "bitcoinErrorShort='${bitcoinErrorShort}'"
2019-04-24 23:56:43 +02:00
bitcoinErrorFull=$(echo ${bitcoinError} | tr -d "'")
2019-04-24 23:28:45 +02:00
echo "bitcoinErrorFull='${bitcoinErrorFull}'"
2019-04-16 21:25:27 +01:00
else
##############################
# Get data from blockchaininfo
##############################
# get total number of blocks
total=$(echo ${blockchaininfo} | jq -r '.blocks')
echo "blockchainHeight=${total}"
# is initial sync of blockchain
initialSync=$(echo ${blockchaininfo} | jq -r '.initialblockdownload' | grep -c 'true')
echo "initialSync=${initialSync}"
# get blockchain sync progress
syncProgress="$(echo ${blockchaininfo} | jq -r '.verificationprogress')"
2019-04-16 21:39:49 +01:00
syncProgress=$(echo $syncProgress | awk '{printf( "%.2f%%", 100 * $1)}' | tr '%' ' ' | tr -s " ")
2019-04-16 21:25:27 +01:00
echo "syncProgress=${syncProgress}"
fi
2019-04-17 18:34:20 +01:00
else
# find out why Bitcoin not running
pathAdd=""
if [ "${chain}" = "test" ]; then
pathAdd="/testnet3"
fi
#### POSSIBLE/SOFT PROBLEMS
# place here in future analysis
#### HARD PROBLEMS
# LOW DISK SPACE
lowDiskSpace=$(sudo tail -n 100 /mnt/hdd/${network}${pathAdd}/debug.log | grep -c "Error: Disk space is low!")
if [ ${lowDiskSpace} -gt 0 ]; then
bitcoinErrorShort="HDD DISK SPACE LOW"
bitcoinErrorFull="HDD DISK SPACE LOW - check what data you can delete on HDD and restart"
fi
#### GENERIC ERROR FIND
# if still no error identified - search logs for genereic error
if [ ${#bitcoinErrorShort} -eq 0 ]; then
2019-04-24 23:56:43 +02:00
bitcoinErrorFull=$(sudo tail -n 100 /mnt/hdd/${network}${pathAdd}/debug.log | grep -c "Error:" | tail -1 | tr -d "'")
2019-04-24 15:52:24 +02:00
if [ ${#bitcoinErrorFull} -gt 0 ]; then
2019-04-17 18:34:20 +01:00
bitcoinErrorShort="Error found in Logs"
fi
fi
# output error if found
if [ ${#bitcoinErrorShort} -gt 0 ]; then
echo "bitcoinErrorShort='${bitcoinErrorShort}'"
echo "bitcoinErrorFull='${bitcoinErrorFull}'"
2019-04-24 16:42:16 +02:00
/home/admin/config.scripts/blitz.systemd.sh log blockchain "ERROR: ${bitcoinErrorShort}"
2019-04-17 18:34:20 +01:00
fi
2019-04-16 21:25:27 +01:00
fi
2019-04-24 16:23:15 +02:00
# count restarts of bitcoind/litecoind
startcountLightning=$(cat systemd.lightning.log 2>/dev/null | grep -c "STARTED")
echo "startcountLightning=${startcountLightning}"
2019-04-16 21:25:27 +01:00
# is LND running
lndRunning=$(systemctl status lnd.service 2>/dev/null | grep -c running)
echo "lndActive=${lndRunning}"
if [ ${lndRunning} -eq 1 ]; then
# get LND info
2019-04-16 21:31:52 +01:00
lndinfo=$(sudo -u bitcoin lncli getinfo 2>/mnt/hdd/temp/.lnd.error)
2019-04-16 21:25:27 +01:00
# check if error on request
2019-04-17 00:03:36 +01:00
lndErrorFull=$(cat /mnt/hdd/temp/.lnd.error 2>/dev/null)
2019-04-24 23:28:45 +02:00
lndErrorShort=''
2019-04-24 23:56:43 +02:00
#rm /mnt/hdd/temp/.lnd.error 2>/dev/null
2019-04-24 23:28:45 +02:00
2019-04-16 21:26:37 +01:00
if [ ${#lndError} -gt 0 ]; then
2019-04-24 23:28:45 +02:00
# scan error for walletLocked as common error
2019-04-24 23:59:30 +02:00
locked=$(echo ${lndError} | grep -c 'Wallet is encrypted')
2019-04-24 23:28:45 +02:00
if [ ${locked} -gt 0 ]; then
echo "walletLocked=1"
else
echo "walletLocked=0"
# if not locked error - then
echo "lndErrorShort='Unkown Error - see logs'"
lndErrorFull=$(echo ${lndErrorFull} | sed 's/[^a-zA-Z0-9 ]//g')
echo "lndErrorFull='${lndErrorFull}'"
/home/admin/config.scripts/blitz.systemd.sh log lightning "ERROR: ${lndErrorFull}"
fi
2019-04-16 21:25:27 +01:00
else
2019-04-23 16:22:29 +02:00
# check if wallet is locked
locked=$(echo ${lndinfo} | grep -c unlock)
if [ ${locked} -gt 0 ]; then
echo "walletLocked=1"
else
echo "walletLocked=0"
fi
2019-04-16 21:25:27 +01:00
# synced to chain
syncedToChain=$(echo ${lndinfo} | jq -r '.synced_to_chain' | grep -c 'true')
echo "syncedToChain=${syncedToChain}"
# lnd scan progress
2019-04-16 21:35:45 +01:00
scanTimestamp=$(echo ${lndinfo} | jq -r '.best_header_timestamp')
2019-04-17 00:06:11 +01:00
if [ ${#scanTimestamp} -gt 0 ]; then
2019-04-24 23:40:27 +02:00
echo "scanTimestamp=${scanTimestamp}"
2019-04-17 00:06:11 +01:00
scanDate=$(date -d @${scanTimestamp})
echo "scanDate='${scanDate}'"
# calculate LND scan progress by seconds since Genesisblock
genesisTimestamp=1230940800
nowTimestamp=$(date +%s)
totalSeconds=$(echo "${nowTimestamp}-${genesisTimestamp}" | bc)
scannedSeconds=$(echo "${scanTimestamp}-${genesisTimestamp}" | bc)
scanProgress=$(echo "scale=2; $scannedSeconds*100/$totalSeconds" | bc)
echo "scanProgress=${scanProgress}"
2019-04-24 23:40:27 +02:00
else
echo "# was not able to parse 'best_header_timestamp' from: lncli getinfo"
echo "scanTimestamp=-1"
2019-04-17 00:06:11 +01:00
fi
2019-04-16 21:25:27 +01:00
fi
fi
# check if online if problem with other stuff
# info on scan run time
endTime=$(date +%s)
runTime=$(echo "${endTime}-${startTime}" | bc)
2019-04-17 00:12:43 +01:00
echo "scriptRuntime=${runTime}"