2018-12-11 13:15:15 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# This script runs on after start in background
|
|
|
|
# as a service and gets restarted on failure
|
|
|
|
# it runs ALMOST every seconds
|
|
|
|
|
|
|
|
# INFOFILE - state data from bootstrap
|
|
|
|
infoFile="/home/admin/raspiblitz.info"
|
|
|
|
|
|
|
|
# CONFIGFILE - configuration of RaspiBlitz
|
|
|
|
configFile="/mnt/hdd/raspiblitz.conf"
|
|
|
|
|
2018-12-23 14:20:13 +01:00
|
|
|
# LOGS see: sudo journalctl -f -u background
|
|
|
|
|
2018-12-23 14:31:58 +01:00
|
|
|
echo "_background.sh STARTED"
|
|
|
|
|
2020-01-25 23:28:33 +01:00
|
|
|
# global vars
|
|
|
|
blitzTUIHeartBeatLine=""
|
2021-12-14 23:34:35 +01:00
|
|
|
/home/admin/_cache.sh set blitzTUIRestarts "0"
|
2020-01-25 23:28:33 +01:00
|
|
|
|
2018-12-11 13:15:15 +01:00
|
|
|
counter=0
|
|
|
|
while [ 1 ]
|
|
|
|
do
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# Prepare this loop
|
|
|
|
###############################
|
|
|
|
|
|
|
|
# count up
|
|
|
|
counter=$(($counter+1))
|
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
# limit counter to max seconds per week:
|
|
|
|
# 604800 = 60sec * 60min * 24hours * 7days
|
|
|
|
if [ ${counter} -gt 604800 ]; then
|
|
|
|
counter=0
|
|
|
|
echo "counter zero reset"
|
|
|
|
fi
|
|
|
|
|
2018-12-22 16:44:15 +01:00
|
|
|
# gather the uptime seconds
|
|
|
|
upSeconds=$(cat /proc/uptime | grep -o '^[0-9]\+')
|
|
|
|
|
2021-12-14 23:34:35 +01:00
|
|
|
# source info & config file fresh on every loop
|
2021-08-04 00:18:30 +02:00
|
|
|
source ${infoFile} 2>/dev/null
|
2021-12-14 23:34:35 +01:00
|
|
|
source ${configFile} 2>/dev/null
|
|
|
|
source <(/home/admin/_cache.sh get state setupPhase)
|
2021-08-04 00:18:30 +02:00
|
|
|
|
|
|
|
####################################################
|
|
|
|
# SKIP BACKGROUND TASK LOOP ON CERTAIN SYSTEM STATES
|
|
|
|
# https://github.com/rootzoll/raspiblitz/issues/160
|
|
|
|
####################################################
|
|
|
|
|
|
|
|
if [ "${state}" == "" ] || [ "${state}" == "copysource" ] || [ "${state}" == "copytarget" ]; then
|
|
|
|
echo "skipping background loop (${counter}) - state(${state})"
|
|
|
|
sleep 1
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# SKIP REST OF THE TASKS IF STILL IN SETUP PHASE
|
|
|
|
####################################################
|
|
|
|
|
|
|
|
if [ "${setupPhase}" != "done" ]; then
|
|
|
|
echo "skipping rest of tasks because still in setupPhase(${setupPhase})"
|
|
|
|
sleep 1
|
2020-10-01 17:30:17 +02:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2018-12-11 13:15:15 +01:00
|
|
|
####################################################
|
2021-09-14 12:30:22 +02:00
|
|
|
# RECHECK DHCP-SERVER
|
2018-12-11 13:15:15 +01:00
|
|
|
# https://github.com/rootzoll/raspiblitz/issues/160
|
|
|
|
####################################################
|
|
|
|
|
|
|
|
# every 5 minutes
|
2018-12-11 13:33:22 +01:00
|
|
|
recheckDHCP=$((($counter % 300)+1))
|
2018-12-11 13:35:00 +01:00
|
|
|
if [ ${recheckDHCP} -eq 1 ]; then
|
2018-12-11 13:15:15 +01:00
|
|
|
echo "*** RECHECK DHCP-SERVER ***"
|
|
|
|
|
|
|
|
# get the local network IP
|
2021-08-04 00:18:30 +02:00
|
|
|
localip=$(hostname -I | awk '{print $1}')
|
2018-12-11 13:15:15 +01:00
|
|
|
echo "localip(${localip})"
|
|
|
|
|
2021-09-14 12:30:22 +02:00
|
|
|
# detect a missing DHCP config
|
2018-12-11 13:15:15 +01:00
|
|
|
if [ "${localip:0:4}" = "169." ]; then
|
|
|
|
echo "Missing DHCP detected ... trying emergency reboot"
|
2021-12-14 23:34:35 +01:00
|
|
|
/home/admin/config.scripts/blitz.shutdown.sh reboot
|
2018-12-11 13:15:15 +01:00
|
|
|
else
|
|
|
|
echo "DHCP OK"
|
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# RECHECK PUBLIC IP
|
2020-10-05 22:45:34 +02:00
|
|
|
#
|
|
|
|
# when public IP changes
|
|
|
|
# - restart bitcoind with new IP
|
|
|
|
# - restart LND with new IP (if autounlock is enabled)
|
|
|
|
# - restart BTCRPCexplorer if enabled in config or running)
|
2018-12-11 13:15:15 +01:00
|
|
|
####################################################
|
|
|
|
|
|
|
|
# every 15min - not too often
|
|
|
|
# because its a ping to external service
|
2019-03-14 14:19:00 +01:00
|
|
|
recheckPublicIP=$((($counter % 900)+1))
|
2021-12-14 23:34:35 +01:00
|
|
|
|
2019-04-03 03:58:10 +02:00
|
|
|
# prevent when lndAddress is set
|
|
|
|
if [ ${#lndAddress} -gt 3 ]; then
|
|
|
|
recheckPublicIP=0
|
|
|
|
fi
|
2020-01-07 21:15:35 +01:00
|
|
|
|
|
|
|
# prevent also when runBehindTor is on
|
|
|
|
if [ "${runBehindTor}" = "1" ] || [ "${runBehindTor}" = "on" ]; then
|
|
|
|
recheckPublicIP=0
|
|
|
|
fi
|
|
|
|
|
2018-12-13 21:59:58 +01:00
|
|
|
updateDynDomain=0
|
2018-12-11 13:35:00 +01:00
|
|
|
if [ ${recheckPublicIP} -eq 1 ]; then
|
2018-12-11 13:15:15 +01:00
|
|
|
echo "*** RECHECK PUBLIC IP ***"
|
|
|
|
|
|
|
|
# execute only after setup when config exists
|
2021-12-14 23:34:35 +01:00
|
|
|
publicIPChanged=$(/home/admin/config.scripts/internet.sh update-publicip | grep -c 'ip_changed=1')
|
2020-09-28 21:40:41 +02:00
|
|
|
|
2020-09-24 21:01:16 +02:00
|
|
|
# check if changed
|
2020-09-28 21:40:41 +02:00
|
|
|
if [ ${publicIPChanged} -gt 0 ]; then
|
2019-01-21 21:40:48 +01:00
|
|
|
|
2020-10-05 22:45:34 +02:00
|
|
|
echo "*** change of public IP detected ***"
|
2021-09-14 12:30:22 +02:00
|
|
|
|
|
|
|
# store the old IP address
|
|
|
|
publicIP_Old="${publicIP}"
|
2020-09-24 21:01:16 +02:00
|
|
|
# refresh data
|
|
|
|
source /mnt/hdd/raspiblitz.conf
|
2021-09-14 12:30:22 +02:00
|
|
|
# store the new IP address
|
|
|
|
publicIP_New="${publicIP}"
|
|
|
|
# some log output
|
|
|
|
echo " old: ${publicIP_Old}"
|
|
|
|
echo " new: ${publicIP_New}"
|
2020-10-05 22:45:34 +02:00
|
|
|
|
|
|
|
# if we run on IPv6 only, the global IPv6 address at the current network device (e.g: eth0) is the public IP
|
|
|
|
if [ "${ipv6}" = "on" ]; then
|
2021-09-14 12:30:22 +02:00
|
|
|
# if the old or the new IPv6 address is "::1" something has gone wrong in "internet.sh update-publicip" => no need to restart services
|
|
|
|
if [ "${publicIP_Old}" != "::1" ] && [ "${publicIP_New}" != "::1" ]; then
|
|
|
|
# restart bitcoind as the global IP is stored in the node configuration
|
|
|
|
# and we will get more connections if this matches our real IP address
|
|
|
|
# otherwise the bitcoin-node connections will slowly decline
|
|
|
|
echo "IPv6 only is enabled => restart bitcoind to pickup up new publicIP as local IP"
|
2021-12-14 23:34:35 +01:00
|
|
|
systemctl stop bitcoind
|
2021-09-14 12:30:22 +02:00
|
|
|
sleep 3
|
2021-12-14 23:34:35 +01:00
|
|
|
systemctl start bitcoind
|
2021-09-14 12:30:22 +02:00
|
|
|
|
|
|
|
# if BTCRPCexplorer is currently running
|
|
|
|
# it needs to be restarted to pickup the new IP for its "Node Status Page"
|
|
|
|
# but this is only needed in IPv6 only mode
|
2021-12-14 23:34:35 +01:00
|
|
|
breIsRunning=$(systemctl status btc-rpc-explorer 2>/dev/null | grep -c 'active (running)')
|
2021-09-14 12:30:22 +02:00
|
|
|
if [ ${breIsRunning} -eq 1 ]; then
|
|
|
|
echo "BTCRPCexplorer is running => restart BTCRPCexplorer to pickup up new publicIP for the bitcoin node"
|
2021-12-14 23:34:35 +01:00
|
|
|
systemctl stop btc-rpc-explorer
|
|
|
|
systemctl start btc-rpc-explorer
|
2021-09-14 12:30:22 +02:00
|
|
|
else
|
|
|
|
echo "new publicIP but no BTCRPCexplorer restart because not running"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "IPv6 only is ON, but publicIP_Old OR publicIP_New is equal ::1 => no need to restart bitcoind nor BTCRPCexplorer"
|
|
|
|
fi
|
2020-10-05 22:45:34 +02:00
|
|
|
else
|
|
|
|
echo "IPv6 only is OFF => no need to restart bitcoind nor BTCRPCexplorer"
|
2021-09-14 12:30:22 +02:00
|
|
|
fi
|
2018-12-13 21:59:58 +01:00
|
|
|
|
2020-09-24 21:01:16 +02:00
|
|
|
# only restart LND if auto-unlock is activated
|
2021-09-14 12:30:22 +02:00
|
|
|
# AND neither the old nor the new IPv6 address is "::1"
|
2020-09-24 21:01:16 +02:00
|
|
|
if [ "${autoUnlock}" = "on" ]; then
|
2021-09-14 12:30:22 +02:00
|
|
|
if [ "${publicIP_Old}" != "::1" ] && [ "${publicIP_New}" != "::1" ]; then
|
|
|
|
echo "restart LND to pickup up new publicIP"
|
2021-12-14 23:34:35 +01:00
|
|
|
systemctl stop lnd
|
|
|
|
systemctl start lnd
|
2021-09-14 12:30:22 +02:00
|
|
|
else
|
|
|
|
echo "publicIP_Old OR publicIP_New is equal ::1 => no need to restart LND"
|
|
|
|
fi
|
2018-12-11 13:15:15 +01:00
|
|
|
else
|
2020-09-24 21:01:16 +02:00
|
|
|
echo "new publicIP but no LND restart because no auto-unlock"
|
2018-12-11 13:15:15 +01:00
|
|
|
fi
|
|
|
|
|
2021-08-27 09:59:21 +02:00
|
|
|
# trigger update if dynamic domain (if set)
|
2020-09-24 21:01:16 +02:00
|
|
|
updateDynDomain=1
|
|
|
|
|
2018-12-11 13:15:15 +01:00
|
|
|
else
|
2020-09-24 21:01:16 +02:00
|
|
|
echo "public IP has not changed"
|
2018-12-11 13:15:15 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
2021-12-14 23:34:35 +01:00
|
|
|
###############################
|
|
|
|
# UPDATE DYNAMIC DOMAIN
|
|
|
|
# like afraid.org
|
|
|
|
# ! experimental
|
|
|
|
###############################
|
|
|
|
|
|
|
|
# if not activated above, update every 6 hours
|
|
|
|
if [ ${updateDynDomain} -eq 0 ]; then
|
|
|
|
# dont +1 so that it gets executed on first loop
|
|
|
|
updateDynDomain=$(($counter % 21600))
|
|
|
|
fi
|
|
|
|
if [ ${updateDynDomain} -eq 1 ]; then
|
|
|
|
echo "*** UPDATE DYNAMIC DOMAIN ***"
|
|
|
|
# check if update URL for dyn Domain is set
|
|
|
|
if [ ${#dynUpdateUrl} -gt 0 ]; then
|
|
|
|
/home/admin/config.scripts/internet.dyndomain.sh update
|
|
|
|
else
|
|
|
|
echo "'dynUpdateUrl' not set in ${configFile}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2020-12-21 00:27:20 +01:00
|
|
|
###############################
|
|
|
|
# Blockchain Sync Monitor
|
|
|
|
###############################
|
|
|
|
|
|
|
|
# check every 1min
|
|
|
|
recheckSync=$(($counter % 60))
|
2021-12-14 23:34:35 +01:00
|
|
|
if [ ${recheckSync} -eq 1 ] && [ "${chain}" == "main" ]; then
|
|
|
|
source <(/home/admin/config.scripts/bitcoin.monitor.sh mainnet network)
|
2021-12-17 22:28:35 +01:00
|
|
|
echo "Blockchain Sync Monitoring: peers=${btc_peers}"
|
2021-12-14 23:34:35 +01:00
|
|
|
if [ "${btc_peers}" == "0" ] && [ "${btc_running}" == "1" ]; then
|
2020-12-21 00:27:20 +01:00
|
|
|
echo "Blockchain Sync Monitoring: ZERO PEERS DETECTED .. doing out-of-band kickstart"
|
2021-12-14 23:34:35 +01:00
|
|
|
/home/admin/config.scripts/bitcoin.monitor.sh mainnet peer-kickstart
|
2020-12-21 00:27:20 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2020-01-25 23:28:33 +01:00
|
|
|
###############################
|
|
|
|
# BlitzTUI Monitoring
|
|
|
|
###############################
|
2019-04-15 13:31:28 +02:00
|
|
|
|
2020-01-25 23:28:33 +01:00
|
|
|
# check every 30sec
|
|
|
|
recheckBlitzTUI=$(($counter % 30))
|
2020-01-25 23:52:57 +01:00
|
|
|
if [ "${touchscreen}" == "1" ] && [ ${recheckBlitzTUI} -eq 1 ]; then
|
2021-12-14 23:34:35 +01:00
|
|
|
|
2020-01-25 23:52:57 +01:00
|
|
|
echo "BlitzTUI Monitoring Check"
|
2020-10-01 17:30:17 +02:00
|
|
|
if [ -d "/var/cache/raspiblitz" ]; then
|
2021-12-14 23:34:35 +01:00
|
|
|
latestHeartBeatLine=$(tail -n 300 /var/cache/raspiblitz/pi/blitz-tui.log | grep beat | tail -n 1)
|
2020-05-30 13:56:24 +02:00
|
|
|
else
|
2021-12-14 23:34:35 +01:00
|
|
|
latestHeartBeatLine=$(tail -n 300 /home/pi/blitz-tui.log | grep beat | tail -n 1)
|
2020-10-01 17:30:17 +02:00
|
|
|
fi
|
|
|
|
if [ ${#blitzTUIHeartBeatLine} -gt 0 ]; then
|
|
|
|
#echo "blitzTUIHeartBeatLine(${blitzTUIHeartBeatLine})"
|
|
|
|
#echo "latestHeartBeatLine(${latestHeartBeatLine})"
|
|
|
|
if [ "${blitzTUIHeartBeatLine}" == "${latestHeartBeatLine}" ]; then
|
|
|
|
echo "FAIL - still no new heart beat .. restarting BlitzTUI"
|
2021-12-14 23:34:35 +01:00
|
|
|
source <(/home/admin/_cache.sh increment system_count_start_tui)
|
|
|
|
init 3 ; sleep 2 ; init 5
|
2020-01-25 23:28:33 +01:00
|
|
|
fi
|
2020-10-01 17:30:17 +02:00
|
|
|
else
|
|
|
|
echo "blitzTUIHeartBeatLine is empty - skipping check"
|
2020-01-25 23:28:33 +01:00
|
|
|
fi
|
2020-10-01 17:30:17 +02:00
|
|
|
blitzTUIHeartBeatLine="${latestHeartBeatLine}"
|
2020-01-25 23:28:33 +01:00
|
|
|
fi
|
2021-09-14 12:30:22 +02:00
|
|
|
|
2019-04-15 15:59:53 +02:00
|
|
|
###############################
|
|
|
|
# SCB Monitoring
|
|
|
|
###############################
|
|
|
|
|
2021-12-14 23:34:35 +01:00
|
|
|
# check every 1min (only when lnd active)
|
|
|
|
recheckSCB=0
|
|
|
|
if [ "${lightning}" == "lnd" ] || [ "${lnd}" == "on" ]; then
|
|
|
|
recheckSCB=$(($counter % 60))
|
|
|
|
fi
|
2019-04-15 15:59:53 +02:00
|
|
|
if [ ${recheckSCB} -eq 1 ]; then
|
2019-04-17 05:44:05 +02:00
|
|
|
#echo "SCB Monitoring ..."
|
2019-04-15 19:45:16 +02:00
|
|
|
source ${configFile}
|
2019-04-15 15:59:53 +02:00
|
|
|
# check if channel.backup exists
|
2020-06-30 16:35:33 +02:00
|
|
|
scbPath=/mnt/hdd/lnd/data/chain/${network}/${chain}net/channel.backup
|
2021-12-14 23:34:35 +01:00
|
|
|
scbExists=$(ls $scbPath 2>/dev/null | grep -c 'channel.backup')
|
2019-04-15 15:59:53 +02:00
|
|
|
if [ ${scbExists} -eq 1 ]; then
|
2021-12-14 23:34:35 +01:00
|
|
|
|
2020-06-30 16:35:33 +02:00
|
|
|
# timestamp backup filename
|
|
|
|
timestampedFileName=channel-$(date "+%Y%m%d-%H%M%S").backup
|
2020-08-14 14:49:00 +02:00
|
|
|
localBackupDir=/home/admin/backups/scb
|
2020-06-30 16:35:33 +02:00
|
|
|
localBackupPath=${localBackupDir}/channel.backup
|
|
|
|
localTimestampedPath=${localBackupDir}/${timestampedFileName}
|
|
|
|
|
2019-04-17 05:44:05 +02:00
|
|
|
#echo "Found Channel Backup File .. check if changed .."
|
2021-12-14 23:34:35 +01:00
|
|
|
md5checksumORG=$(md5sum $scbPath 2>/dev/null | head -n1 | cut -d " " -f1)
|
|
|
|
md5checksumCPY=$(md5sum $localBackupPath 2>/dev/null | head -n1 | cut -d " " -f1)
|
2019-04-15 15:59:53 +02:00
|
|
|
if [ "${md5checksumORG}" != "${md5checksumCPY}" ]; then
|
|
|
|
echo "--> Channel Backup File changed"
|
2019-04-15 19:45:16 +02:00
|
|
|
|
|
|
|
# make copy to sd card (as local basic backup)
|
2021-12-14 23:34:35 +01:00
|
|
|
mkdir -p /home/admin/backups/scb/ 2>/dev/null
|
|
|
|
cp $scbPath $localBackupPath
|
|
|
|
cp $scbPath $localTimestampedPath
|
|
|
|
cp $scbPath /boot/channel.backup
|
2021-12-20 20:41:02 +01:00
|
|
|
echo "OK channel.backup copied to '${localBackupPath}' and '${localTimestampedPath}' and '/boot/channel.backup'"
|
2020-06-30 16:35:33 +02:00
|
|
|
|
2020-07-04 01:00:15 +02:00
|
|
|
# check if a additional local backup target is set
|
2020-07-04 14:03:41 +02:00
|
|
|
# see ./config.scripts/blitz.backupdevice.sh
|
|
|
|
if [ "${localBackupDeviceUUID}" != "" ] && [ "${localBackupDeviceUUID}" != "off" ]; then
|
2020-07-04 01:00:15 +02:00
|
|
|
|
|
|
|
# check if device got mounted on "/mnt/backup" (gets mounted by _bootstrap.sh)
|
|
|
|
backupDeviceExists=$(df | grep -c "/mnt/backup")
|
|
|
|
if [ ${backupDeviceExists} -gt 0 ]; then
|
|
|
|
|
|
|
|
echo "--> Additional Local Backup Device"
|
2021-12-14 23:34:35 +01:00
|
|
|
cp ${localBackupPath} /mnt/backup/
|
|
|
|
cp ${localTimestampedPath} /mnt/backup/
|
2020-07-04 01:00:15 +02:00
|
|
|
|
2021-08-27 09:59:21 +02:00
|
|
|
# check results
|
2020-07-04 01:00:15 +02:00
|
|
|
result=$?
|
|
|
|
if [ ${result} -eq 0 ]; then
|
2021-08-27 09:59:21 +02:00
|
|
|
echo "OK - Successful Copy to additional Backup Device"
|
2020-07-04 01:00:15 +02:00
|
|
|
else
|
|
|
|
echo "FAIL - Copy to additional Backup Device exited with ${result}"
|
|
|
|
fi
|
|
|
|
|
2020-06-30 17:00:54 +02:00
|
|
|
else
|
2020-07-04 01:00:15 +02:00
|
|
|
echo "FAIL - BackupDrive mount - check if device is connected & UUID is correct" >> $logFile
|
2020-06-30 17:00:54 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-04-15 19:45:16 +02:00
|
|
|
# check if a SCP backup target is set
|
2020-05-01 20:51:15 +02:00
|
|
|
# parameter in raspiblitz.conf:
|
2019-04-15 20:54:07 +02:00
|
|
|
# scpBackupTarget='[USER]@[SERVER]:[DIRPATH-WITHOUT-ENDING-/]'
|
2021-08-17 17:59:38 +02:00
|
|
|
# optionally a custom option string for the scp command can be set with
|
|
|
|
# scpBackupOptions='[YOUR-CUSTOM-OPTIONS]'
|
2019-04-15 19:45:16 +02:00
|
|
|
# On target server add the public key of your RaspiBlitz to the authorized_keys for the user
|
|
|
|
# https://www.linode.com/docs/security/authentication/use-public-key-authentication-with-ssh/
|
|
|
|
if [ ${#scpBackupTarget} -gt 0 ]; then
|
|
|
|
echo "--> Offsite-Backup SCP Server"
|
2021-08-17 17:59:38 +02:00
|
|
|
if [ "${scpBackupOptions}" == "" ]; then
|
|
|
|
scpBackupOptions="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
|
2021-12-14 23:34:35 +01:00
|
|
|
fi
|
2019-04-16 03:10:58 +02:00
|
|
|
# its ok to ignore known host, because data is encrypted (worst case of MiM would be: no offsite channel backup)
|
2020-05-01 20:51:15 +02:00
|
|
|
# but its more likely that without ignoring known host, script might not run thru and that way: no offsite channel backup
|
2021-12-14 23:34:35 +01:00
|
|
|
scp ${scpBackupOptions} ${localBackupPath} ${scpBackupTarget}/
|
|
|
|
scp ${scpBackupOptions} ${localTimestampedPath} ${scpBackupTarget}/
|
2019-04-15 20:37:41 +02:00
|
|
|
result=$?
|
|
|
|
if [ ${result} -eq 0 ]; then
|
|
|
|
echo "OK - SCP Backup exited with 0"
|
|
|
|
else
|
|
|
|
echo "FAIL - SCP Backup exited with ${result}"
|
|
|
|
fi
|
2019-04-15 19:45:16 +02:00
|
|
|
fi
|
|
|
|
|
2021-09-14 17:36:54 +02:00
|
|
|
# check if Nextcloud backups are enabled
|
|
|
|
if [ $nextcloudBackupServer ] && [ $nextcloudBackupUser ] && [ $nextcloudBackupPassword ]; then
|
|
|
|
echo "--> Offsite-Backup Nextcloud"
|
2021-12-14 23:34:35 +01:00
|
|
|
source <(/home/admin/config.scripts/nextcloud.upload.sh upload ${localBackupPath})
|
|
|
|
source <(/home/admin/config.scripts/nextcloud.upload.sh upload ${localTimestampedPath})
|
2021-09-14 17:36:54 +02:00
|
|
|
if [ ${#err} -gt 0 ]; then
|
|
|
|
echo "FAIL - ${err}"
|
|
|
|
else
|
|
|
|
echo "OK - ${upload}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-04-17 05:44:05 +02:00
|
|
|
#else
|
|
|
|
# echo "Channel Backup File not changed."
|
2019-04-15 15:59:53 +02:00
|
|
|
fi
|
2019-04-17 05:44:05 +02:00
|
|
|
#else
|
|
|
|
# echo "No Channel Backup File .."
|
2019-04-15 15:59:53 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2020-05-27 00:15:02 +02:00
|
|
|
###############################
|
|
|
|
# SUBSCRIPTION RENWES
|
|
|
|
###############################
|
|
|
|
|
2020-07-15 14:49:42 +02:00
|
|
|
# check every 20min
|
|
|
|
recheckSubscription=$((($counter % 1200)+1))
|
2020-05-27 00:15:02 +02:00
|
|
|
if [ ${recheckSubscription} -eq 1 ]; then
|
|
|
|
# IP2TOR subscriptions (that will need renew in next 20min = 1200 secs)
|
2020-07-15 14:49:42 +02:00
|
|
|
sudo -u admin /home/admin/config.scripts/blitz.subscriptions.ip2tor.py subscriptions-renew 1800
|
2020-05-27 00:15:02 +02:00
|
|
|
fi
|
|
|
|
|
2019-12-12 10:26:21 +01:00
|
|
|
###############################
|
|
|
|
# RAID data check (BRTFS)
|
|
|
|
###############################
|
|
|
|
# see https://github.com/rootzoll/raspiblitz/issues/360#issuecomment-467698260
|
|
|
|
|
|
|
|
# check every hour
|
2020-05-27 00:15:02 +02:00
|
|
|
recheckRAID=$((($counter % 3600)+1))
|
2019-12-12 10:26:21 +01:00
|
|
|
if [ ${recheckRAID} -eq 1 ]; then
|
2021-09-14 12:30:22 +02:00
|
|
|
|
2021-12-14 23:34:35 +01:00
|
|
|
# check if BTRTFS raid is active & scrub
|
|
|
|
source <(/home/admin/config.scripts/blitz.datadrive.sh status)
|
|
|
|
if [ "${isBTRFS}" == "1" ] && [ "${isRaid}" == "1" ]; then
|
2019-12-12 10:26:21 +01:00
|
|
|
echo "STARTING BTRFS RAID DATA CHECK ..."
|
2021-12-14 23:34:35 +01:00
|
|
|
btrfs scrub start /mnt/hdd/
|
2019-12-12 10:26:21 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
2018-12-13 21:59:58 +01:00
|
|
|
###############################
|
2018-12-22 16:44:15 +01:00
|
|
|
# LND AUTO-UNLOCK
|
|
|
|
###############################
|
|
|
|
|
2021-12-14 23:34:35 +01:00
|
|
|
# check every 10secs (only if LND is active)
|
|
|
|
recheckAutoUnlock=0
|
|
|
|
if [ "${lightning}" == "lnd" ] || [ "${lnd}" == "on" ]; then
|
|
|
|
recheckAutoUnlock=$((($counter % 10)+1))
|
|
|
|
fi
|
2018-12-22 16:44:15 +01:00
|
|
|
if [ ${recheckAutoUnlock} -eq 1 ]; then
|
|
|
|
|
|
|
|
# check if auto-unlock feature if activated
|
|
|
|
if [ "${autoUnlock}" = "on" ]; then
|
|
|
|
|
|
|
|
# check if lnd is locked
|
2021-08-04 00:18:30 +02:00
|
|
|
source <(/home/admin/config.scripts/lnd.unlock.sh status)
|
|
|
|
if [ "${locked}" != "0" ]; then
|
2018-12-22 16:44:15 +01:00
|
|
|
|
2018-12-23 15:47:01 +01:00
|
|
|
echo "STARTING AUTO-UNLOCK ..."
|
2021-12-14 23:34:35 +01:00
|
|
|
/home/admin/config.scripts/lnd.unlock.sh
|
2021-09-14 12:30:22 +02:00
|
|
|
|
2018-12-22 16:44:15 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-08-08 02:15:44 +02:00
|
|
|
####################################################
|
|
|
|
# CHECK FOR END OF IBD (self validation)
|
|
|
|
####################################################
|
|
|
|
|
|
|
|
# check every 60secs
|
|
|
|
recheckIBD=$((($counter % 60)+1))
|
|
|
|
if [ ${recheckIBD} -eq 1 ]; then
|
|
|
|
# check if flag exists (got created on 50syncHDD.sh)
|
2021-08-04 00:18:30 +02:00
|
|
|
flagExists=$(ls /mnt/hdd/${network}/blocks/selfsync.flag 2>/dev/null | grep -c "selfsync.flag")
|
2019-08-08 02:15:44 +02:00
|
|
|
if [ ${flagExists} -eq 1 ]; then
|
2021-08-04 00:18:30 +02:00
|
|
|
source <(/home/admin/config.scripts/network.aliases.sh getvars)
|
|
|
|
finishedIBD=$($bitcoincli_alias getblockchaininfo | grep "initialblockdownload" | grep -c "false")
|
2019-08-08 02:15:44 +02:00
|
|
|
if [ ${finishedIBD} -eq 1 ]; then
|
|
|
|
|
2021-10-28 01:00:32 +02:00
|
|
|
echo "CHECK FOR END OF IBD --> reduce RAM for next reboot"
|
2019-08-08 02:19:26 +02:00
|
|
|
|
2019-08-08 02:15:44 +02:00
|
|
|
# remove flag
|
2021-12-14 23:34:35 +01:00
|
|
|
rm /mnt/hdd/${network}/blocks/selfsync.flag
|
2019-08-08 02:15:44 +02:00
|
|
|
|
2021-10-28 01:00:32 +02:00
|
|
|
# set dbcache back to normal (to give room for other apps after reboot in the future)
|
2021-12-14 23:34:35 +01:00
|
|
|
kbSizeRAM=$(cat /proc/meminfo | grep "MemTotal" | sed 's/[^0-9]*//g')
|
|
|
|
|
2019-08-08 02:15:44 +02:00
|
|
|
if [ ${kbSizeRAM} -gt 1500000 ]; then
|
|
|
|
echo "Detected RAM >1GB --> optimizing ${network}.conf"
|
2021-12-14 23:34:35 +01:00
|
|
|
sed -i "s/^dbcache=.*/dbcache=512/g" /mnt/hdd/${network}/${network}.conf
|
2019-08-08 02:15:44 +02:00
|
|
|
else
|
|
|
|
echo "Detected RAM 1GB --> optimizing ${network}.conf"
|
2021-12-14 23:34:35 +01:00
|
|
|
sed -i "s/^dbcache=.*/dbcache=128/g" /mnt/hdd/${network}/${network}.conf
|
2019-08-08 02:15:44 +02:00
|
|
|
fi
|
|
|
|
|
2021-12-14 23:34:35 +01:00
|
|
|
# relax sanning on sync progress (after 30 more secs)
|
|
|
|
/home/admin/_cache.sh focus btc_default_sync_progress 10 30
|
|
|
|
|
2019-08-08 02:15:44 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2018-12-11 13:15:15 +01:00
|
|
|
###############################
|
|
|
|
# Prepare next loop
|
|
|
|
###############################
|
|
|
|
|
|
|
|
# sleep 1 sec
|
|
|
|
sleep 1
|
|
|
|
|
2021-12-14 23:34:35 +01:00
|
|
|
done
|