mirror of
https://github.com/raspiblitz/raspiblitz.git
synced 2025-03-27 02:01:53 +01:00
Minimize service restarts (#2207)
* whitespaces, fix typos, more logging * whitespaces, typos, more validation for IPv6 to do less service restarts
This commit is contained in:
parent
ab0fbef5fc
commit
03a8e10088
@ -84,7 +84,7 @@ do
|
||||
fi
|
||||
|
||||
####################################################
|
||||
# RECHECK DHCP-SERVER
|
||||
# RECHECK DHCP-SERVER
|
||||
# https://github.com/rootzoll/raspiblitz/issues/160
|
||||
####################################################
|
||||
|
||||
@ -97,7 +97,7 @@ do
|
||||
localip=$(hostname -I | awk '{print $1}')
|
||||
echo "localip(${localip})"
|
||||
|
||||
# detect a missing DHCP config
|
||||
# detect a missing DHCP config
|
||||
if [ "${localip:0:4}" = "169." ]; then
|
||||
echo "Missing DHCP detected ... trying emergency reboot"
|
||||
sudo /home/admin/config.scripts/blitz.shutdown.sh reboot
|
||||
@ -161,42 +161,57 @@ do
|
||||
if [ ${publicIPChanged} -gt 0 ]; then
|
||||
|
||||
echo "*** change of public IP detected ***"
|
||||
echo " old: ${publicIP}"
|
||||
|
||||
# store the old IP address
|
||||
publicIP_Old="${publicIP}"
|
||||
# refresh data
|
||||
source /mnt/hdd/raspiblitz.conf
|
||||
echo " new: ${publicIP}"
|
||||
# store the new IP address
|
||||
publicIP_New="${publicIP}"
|
||||
# some log output
|
||||
echo " old: ${publicIP_Old}"
|
||||
echo " new: ${publicIP_New}"
|
||||
|
||||
# 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
|
||||
# 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"
|
||||
sudo systemctl stop bitcoind
|
||||
sleep 3
|
||||
sudo systemctl start bitcoind
|
||||
|
||||
# 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
|
||||
breIsRunning=$(sudo systemctl status btc-rpc-explorer 2>/dev/null | grep -c 'active (running)')
|
||||
if [ ${breIsRunning} -eq 1 ]; then
|
||||
echo "BTCRPCexplorer is running => restart BTCRPCexplorer to pickup up new publicIP for the bitcoin node"
|
||||
sudo systemctl stop btc-rpc-explorer
|
||||
sudo systemctl start btc-rpc-explorer
|
||||
else
|
||||
echo "new publicIP but no BTCRPCexplorer restart because not running"
|
||||
fi
|
||||
# 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"
|
||||
sudo systemctl stop bitcoind
|
||||
sleep 3
|
||||
sudo systemctl start bitcoind
|
||||
|
||||
# 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
|
||||
breIsRunning=$(sudo systemctl status btc-rpc-explorer 2>/dev/null | grep -c 'active (running)')
|
||||
if [ ${breIsRunning} -eq 1 ]; then
|
||||
echo "BTCRPCexplorer is running => restart BTCRPCexplorer to pickup up new publicIP for the bitcoin node"
|
||||
sudo systemctl stop btc-rpc-explorer
|
||||
sudo systemctl start btc-rpc-explorer
|
||||
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
|
||||
else
|
||||
echo "IPv6 only is OFF => no need to restart bitcoind nor BTCRPCexplorer"
|
||||
fi
|
||||
fi
|
||||
|
||||
# only restart LND if auto-unlock is activated
|
||||
# AND neither the old nor the new IPv6 address is "::1"
|
||||
if [ "${autoUnlock}" = "on" ]; then
|
||||
echo "restart LND to pickup up new publicIP"
|
||||
sudo systemctl stop lnd
|
||||
sudo systemctl start lnd
|
||||
if [ "${publicIP_Old}" != "::1" ] && [ "${publicIP_New}" != "::1" ]; then
|
||||
echo "restart LND to pickup up new publicIP"
|
||||
sudo systemctl stop lnd
|
||||
sudo systemctl start lnd
|
||||
else
|
||||
echo "publicIP_Old OR publicIP_New is equal ::1 => no need to restart LND"
|
||||
fi
|
||||
else
|
||||
echo "new publicIP but no LND restart because no auto-unlock"
|
||||
fi
|
||||
@ -255,7 +270,7 @@ do
|
||||
fi
|
||||
blitzTUIHeartBeatLine="${latestHeartBeatLine}"
|
||||
fi
|
||||
|
||||
|
||||
###############################
|
||||
# SCB Monitoring
|
||||
###############################
|
||||
@ -380,7 +395,7 @@ do
|
||||
# check every hour
|
||||
recheckRAID=$((($counter % 3600)+1))
|
||||
if [ ${recheckRAID} -eq 1 ]; then
|
||||
|
||||
|
||||
# check if raid is active
|
||||
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status)
|
||||
if [ ${isRaid} -eq 1 ]; then
|
||||
@ -410,7 +425,7 @@ do
|
||||
|
||||
echo "STARTING AUTO-UNLOCK ..."
|
||||
sudo /home/admin/config.scripts/lnd.unlock.sh
|
||||
|
||||
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
@ -135,14 +135,17 @@ if [ ${runGlobal} -eq 1 ]; then
|
||||
else
|
||||
globalIP=$(curl -s -f -S -m 5 http://v4.ipv6-test.com/api/myip.php 2>/dev/null)
|
||||
fi
|
||||
echo "## curl returned: ${globalIP}"
|
||||
echo "## curl exit code: ${?}"
|
||||
|
||||
|
||||
# sanity check on IP data
|
||||
# see https://github.com/rootzoll/raspiblitz/issues/371#issuecomment-472416349
|
||||
echo "# sanity check of IP data:"
|
||||
if [[ $globalIP =~ ^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$ ]]; then
|
||||
echo "# OK IPv6"
|
||||
echo "# OK IPv6 for ${globalIP}"
|
||||
elif [[ $globalIP =~ ^([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$ ]]; then
|
||||
echo "# OK IPv4"
|
||||
echo "# OK IPv4 for ${globalIP}"
|
||||
else
|
||||
echo "# FAIL - not an IPv4 or IPv6 address"
|
||||
globalIP=""
|
||||
@ -164,7 +167,7 @@ if [ ${runGlobal} -eq 1 ]; then
|
||||
if [ "${publicIP}" == "" ]; then
|
||||
# if publicIP is not set by config ... use detected global IP
|
||||
if [ "${ipv6}" == "on" ]; then
|
||||
# use ipv6 with brackets so that it can be used in http addresses like a IPv4
|
||||
# use ipv6 with square brackets so that it can be used in http addresses like a IPv4
|
||||
publicIP="[${globalIP}]"
|
||||
else
|
||||
publicIP="${globalIP}"
|
||||
@ -193,7 +196,7 @@ if [ "$1" == "status" ]; then
|
||||
echo "online=${online}"
|
||||
if [ ${runGlobal} -eq 1 ]; then
|
||||
echo "ipv6=${ipv6}"
|
||||
echo "# globalip --> ip detected from the outside"
|
||||
echo "# globalip --> ip detected from the outside"
|
||||
echo "globalip=${globalIP}"
|
||||
echo "# publicip --> may consider the static IP overide by raspiblitz config"
|
||||
echo "publicip=${publicIP}"
|
||||
@ -215,7 +218,7 @@ elif [ "$1" == "update-publicip" ]; then
|
||||
else
|
||||
echo "ip_changed=1"
|
||||
if [ "${ipv6}" == "on" ]; then
|
||||
# use ipv6 with brackets so that it can be used in http addresses like a IPv4
|
||||
# use ipv6 with square brackets so that it can be used in http addresses like an IPv4
|
||||
publicIP="[${globalIP}]"
|
||||
else
|
||||
publicIP="${globalIP}"
|
||||
@ -225,7 +228,7 @@ elif [ "$1" == "update-publicip" ]; then
|
||||
|
||||
# store to raspiblitz.conf new publiciP
|
||||
publicIPValueExists=$(sudo cat /mnt/hdd/raspiblitz.conf | grep -c 'publicIP=')
|
||||
if [ ${publicIPValueExists} -gt 1 ]; then
|
||||
if [ ${publicIPValueExists} -gt 1 ]; then
|
||||
# more then one publiIp entry - removing one
|
||||
sudo sed -i "s/^publicIP=.*//g" /mnt/hdd/raspiblitz.conf
|
||||
fi
|
||||
|
Loading…
x
Reference in New Issue
Block a user