mirror of
https://github.com/raspiblitz/raspiblitz.git
synced 2025-08-08 17:23:35 +02: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:
@@ -161,13 +161,21 @@ 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
|
||||
# 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
|
||||
@@ -187,16 +195,23 @@ do
|
||||
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
|
||||
|
||||
# only restart LND if auto-unlock is activated
|
||||
# AND neither the old nor the new IPv6 address is "::1"
|
||||
if [ "${autoUnlock}" = "on" ]; then
|
||||
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
|
||||
|
@@ -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}"
|
||||
@@ -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}"
|
||||
|
Reference in New Issue
Block a user