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:
PatrickScheich
2021-09-14 12:30:22 +02:00
committed by GitHub
parent ab0fbef5fc
commit 03a8e10088
2 changed files with 54 additions and 36 deletions

View File

@@ -161,13 +161,21 @@ do
if [ ${publicIPChanged} -gt 0 ]; then if [ ${publicIPChanged} -gt 0 ]; then
echo "*** change of public IP detected ***" echo "*** change of public IP detected ***"
echo " old: ${publicIP}"
# store the old IP address
publicIP_Old="${publicIP}"
# refresh data # refresh data
source /mnt/hdd/raspiblitz.conf 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 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 [ "${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 # 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 # and we will get more connections if this matches our real IP address
# otherwise the bitcoin-node connections will slowly decline # otherwise the bitcoin-node connections will slowly decline
@@ -187,16 +195,23 @@ do
else else
echo "new publicIP but no BTCRPCexplorer restart because not running" echo "new publicIP but no BTCRPCexplorer restart because not running"
fi 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 else
echo "IPv6 only is OFF => no need to restart bitcoind nor BTCRPCexplorer" echo "IPv6 only is OFF => no need to restart bitcoind nor BTCRPCexplorer"
fi fi
# only restart LND if auto-unlock is activated # only restart LND if auto-unlock is activated
# AND neither the old nor the new IPv6 address is "::1"
if [ "${autoUnlock}" = "on" ]; then if [ "${autoUnlock}" = "on" ]; then
if [ "${publicIP_Old}" != "::1" ] && [ "${publicIP_New}" != "::1" ]; then
echo "restart LND to pickup up new publicIP" echo "restart LND to pickup up new publicIP"
sudo systemctl stop lnd sudo systemctl stop lnd
sudo systemctl start lnd sudo systemctl start lnd
else
echo "publicIP_Old OR publicIP_New is equal ::1 => no need to restart LND"
fi
else else
echo "new publicIP but no LND restart because no auto-unlock" echo "new publicIP but no LND restart because no auto-unlock"
fi fi

View File

@@ -135,14 +135,17 @@ if [ ${runGlobal} -eq 1 ]; then
else else
globalIP=$(curl -s -f -S -m 5 http://v4.ipv6-test.com/api/myip.php 2>/dev/null) globalIP=$(curl -s -f -S -m 5 http://v4.ipv6-test.com/api/myip.php 2>/dev/null)
fi fi
echo "## curl returned: ${globalIP}"
echo "## curl exit code: ${?}"
# sanity check on IP data # sanity check on IP data
# see https://github.com/rootzoll/raspiblitz/issues/371#issuecomment-472416349 # see https://github.com/rootzoll/raspiblitz/issues/371#issuecomment-472416349
echo "# sanity check of IP data:" 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 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 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 else
echo "# FAIL - not an IPv4 or IPv6 address" echo "# FAIL - not an IPv4 or IPv6 address"
globalIP="" globalIP=""
@@ -164,7 +167,7 @@ if [ ${runGlobal} -eq 1 ]; then
if [ "${publicIP}" == "" ]; then if [ "${publicIP}" == "" ]; then
# if publicIP is not set by config ... use detected global IP # if publicIP is not set by config ... use detected global IP
if [ "${ipv6}" == "on" ]; then 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}]" publicIP="[${globalIP}]"
else else
publicIP="${globalIP}" publicIP="${globalIP}"
@@ -215,7 +218,7 @@ elif [ "$1" == "update-publicip" ]; then
else else
echo "ip_changed=1" echo "ip_changed=1"
if [ "${ipv6}" == "on" ]; then 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}]" publicIP="[${globalIP}]"
else else
publicIP="${globalIP}" publicIP="${globalIP}"