#386 set external lndAddress

This commit is contained in:
Christian Rotzoll
2019-04-03 02:58:10 +01:00
parent 1a6234f866
commit 88078e9a40
6 changed files with 78 additions and 33 deletions

View File

@@ -87,7 +87,7 @@ if [ ${existsHDD} -gt 0 ]; then
echo "WARNING: No publicIP information at all yet - working with placeholder : ${localIP}" echo "WARNING: No publicIP information at all yet - working with placeholder : ${localIP}"
freshPublicIP="${localIP}" freshPublicIP="${localIP}"
fi fi
echo "publicIP=${freshPublicIP}" >> $configFile echo "publicIP='${freshPublicIP}'" >> $configFile
fi fi

View File

@@ -87,6 +87,10 @@ do
# every 15min - not too often # every 15min - not too often
# because its a ping to external service # because its a ping to external service
recheckPublicIP=$((($counter % 900)+1)) recheckPublicIP=$((($counter % 900)+1))
# prevent when lndAddress is set
if [ ${#lndAddress} -gt 3 ]; then
recheckPublicIP=0
fi
updateDynDomain=0 updateDynDomain=0
if [ ${recheckPublicIP} -eq 1 ]; then if [ ${recheckPublicIP} -eq 1 ]; then
echo "*** RECHECK PUBLIC IP ***" echo "*** RECHECK PUBLIC IP ***"
@@ -120,8 +124,8 @@ do
# 1) update config file # 1) update config file
echo "update config value" echo "update config value"
sed -i "s/^publicIP=.*/publicIP=${freshPublicIP}/g" ${configFile} sed -i "s/^publicIP=.*/publicIP='${freshPublicIP}'/g" ${configFile}
publicIP=${freshPublicIP} publicIP='${freshPublicIP}'
# 2) only restart LND if dynDNS is activated # 2) only restart LND if dynDNS is activated
# because this signals that user wants "public node" # because this signals that user wants "public node"

View File

@@ -302,9 +302,32 @@ echo "Check if HDD contains configuration .." >> $logFile
configExists=$(ls ${configFile} | grep -c '.conf') configExists=$(ls ${configFile} | grep -c '.conf')
if [ ${configExists} -eq 1 ]; then if [ ${configExists} -eq 1 ]; then
# make sure lndAddress & lndPort exist
valueExists=$(cat ${configFile} | grep -c 'lndPort=')
if [ ${valueExists} -eq 0 ]; then
lndPort=$(sudo cat /mnt/hdd/lnd/lnd.conf | grep "^listen=*" | cut -f2 -d':')
if [ ${#lndPort} -eq 0 ]; then
lndPort="9735"
fi
echo "lndPort='${lndPort}'" >> ${configFile}
fi
valueExists=$(cat ${configFile} | grep -c 'lndAddress=')
if [ ${valueExists} -eq 0 ]; then
echo "lndAddress=''" >> ${configFile}
fi
# load values # load values
echo "load and update publicIP" >> $logFile echo "load and update publicIP" >> $logFile
source ${configFile} source ${configFile}
freshPublicIP=""
# determine the publicIP/domain that LND should announce
if [ ${#lndAddress} -gt 3 ]; then
# use domain as PUBLICIP
freshPublicIP="${lndAddress}"
else
# update public IP on boot # update public IP on boot
# wait otherwise looking for publicIP fails # wait otherwise looking for publicIP fails
@@ -332,8 +355,12 @@ if [ ${configExists} -eq 1 ]; then
freshPublicIP="${localIP}" freshPublicIP="${localIP}"
fi fi
fi fi
fi
# set publicip value in raspiblitz.conf
if [ ${#freshPublicIP} -eq 0 ]; then if [ ${#freshPublicIP} -eq 0 ]; then
echo "WARNING: Was not able to determine external IP on startup." >> $logFile echo "WARNING: Was not able to determine external IP/domain on startup." >> $logFile
else else
publicIPValueExists=$( sudo cat ${configFile} | grep -c 'publicIP=' ) publicIPValueExists=$( sudo cat ${configFile} | grep -c 'publicIP=' )
if [ ${publicIPValueExists} -gt 1 ]; then if [ ${publicIPValueExists} -gt 1 ]; then
@@ -344,10 +371,10 @@ if [ ${configExists} -eq 1 ]; then
fi fi
if [ ${publicIPValueExists} -eq 0 ]; then if [ ${publicIPValueExists} -eq 0 ]; then
echo "create value (${freshPublicIP})" >> $logFile echo "create value (${freshPublicIP})" >> $logFile
echo "publicIP=${freshPublicIP}" >> $configFile echo "publicIP='${freshPublicIP}'" >> $configFile
else else
echo "update value (${freshPublicIP})" >> $logFile echo "update value (${freshPublicIP})" >> $logFile
sed -i "s/^publicIP=.*/publicIP=${freshPublicIP}/g" ${configFile} sed -i "s/^publicIP=.*/publicIP='${freshPublicIP}'/g" ${configFile}
fi fi
fi fi

View File

@@ -10,7 +10,7 @@ After=bitcoind.service
[Service] [Service]
EnvironmentFile=/mnt/hdd/raspiblitz.conf EnvironmentFile=/mnt/hdd/raspiblitz.conf
ExecStart=/usr/local/bin/lnd --externalip=${publicIP} ExecStart=/usr/local/bin/lnd --externalip=${publicIP}:{lndPort}
PIDFile=/home/bitcoin/.lnd/lnd.pid PIDFile=/home/bitcoin/.lnd/lnd.pid
User=bitcoin User=bitcoin
Group=bitcoin Group=bitcoin

View File

@@ -37,6 +37,11 @@ StandardOutput=journal
WantedBy=multi-user.target WantedBy=multi-user.target
""" """
# get LND port form lnd.conf
LNDPORT = subprocess.getoutput("sudo cat /mnt/hdd/lnd/lnd.conf | grep '^listen=*' | cut -f2 -d':'")
if len(LNDPORT) == 0:
LNDPORT="9735"
# #
# RESTORE = SWITCHING ON with restore flag on # RESTORE = SWITCHING ON with restore flag on
# on restore other external scripts dont need calling # on restore other external scripts dont need calling
@@ -93,6 +98,11 @@ if sys.argv[1] == "on":
if port_external.isdigit() == False: if port_external.isdigit() == False:
print("[INTERNAL-PORT]<[EXTERNAL-PORT] external not number '%s'" % (sys.argv[i])) print("[INTERNAL-PORT]<[EXTERNAL-PORT] external not number '%s'" % (sys.argv[i]))
sys.exit(1) sys.exit(1)
if port_internal == LNDPORT:
if port_internal != port_external:
print("FAIL: When tunneling your local LND port '%s' it needs to be the same on the external server, but is '%s'" % (LNDPORT,port_external))
print("Try again by using the same port. If you cant change the external port, change local LND port with: /home/config.scripts/lnd.setport.sh")
sys.exit(1)
ssh_ports = ssh_ports + "\"%s\" " % (sys.argv[i]) ssh_ports = ssh_ports + "\"%s\" " % (sys.argv[i])
additional_parameters= additional_parameters + "-R %s:localhost:%s " % (port_external,port_internal) additional_parameters= additional_parameters + "-R %s:localhost:%s " % (port_external,port_internal)
@@ -140,6 +150,9 @@ if sys.argv[1] == "on":
if file_content.count("sshtunnel=") == 0: if file_content.count("sshtunnel=") == 0:
file_content = file_content+"\nsshtunnel=''" file_content = file_content+"\nsshtunnel=''"
file_content = re.sub("sshtunnel=.*", "sshtunnel='%s %s'" % (ssh_server, ssh_ports), file_content) file_content = re.sub("sshtunnel=.*", "sshtunnel='%s %s'" % (ssh_server, ssh_ports), file_content)
if restoringOnUpdate == False:
serverdomain=ssh_server.split("@")[1]
file_content = re.sub("lndAddress=.*", "lndAddress='%s'" % (serverdomain), file_content)
file_content = "".join([s for s in file_content.splitlines(True) if s.strip("\r\n")]) + "\n" file_content = "".join([s for s in file_content.splitlines(True) if s.strip("\r\n")]) + "\n"
print(file_content) print(file_content)
with open("/mnt/hdd/raspiblitz.conf", "w") as text_file: with open("/mnt/hdd/raspiblitz.conf", "w") as text_file:
@@ -189,6 +202,7 @@ elif sys.argv[1] == "off":
with open('/mnt/hdd/raspiblitz.conf') as f: with open('/mnt/hdd/raspiblitz.conf') as f:
file_content = f.read() file_content = f.read()
file_content = re.sub("sshtunnel=.*", "", file_content) file_content = re.sub("sshtunnel=.*", "", file_content)
file_content = re.sub("lndAddress=.*", "lndAddress=''", file_content)
file_content = re.sub("\n\n", "\n", file_content) file_content = re.sub("\n\n", "\n", file_content)
print(file_content) print(file_content)
with open("/mnt/hdd/raspiblitz.conf", "w") as text_file: with open("/mnt/hdd/raspiblitz.conf", "w") as text_file:

View File

@@ -64,18 +64,18 @@ echo "change port in lnd config"
sudo sed -i "s/^listen=.*/listen=0.0.0.0:${portnumber}/g" /mnt/hdd/lnd/lnd.conf sudo sed -i "s/^listen=.*/listen=0.0.0.0:${portnumber}/g" /mnt/hdd/lnd/lnd.conf
# add to raspiblitz.config (so it can survive update) # add to raspiblitz.config (so it can survive update)
valueExists=$(sudo cat /mnt/hdd/raspiblitz.conf | grep -c 'customPortLND=') valueExists=$(sudo cat /mnt/hdd/raspiblitz.conf | grep -c 'lndPort=')
if [ ${valueExists} -eq 0 ]; then if [ ${valueExists} -eq 0 ]; then
# add as new value # add as new value
echo "customPortLND=${portnumber}" >> /mnt/hdd/raspiblitz.conf echo "lndPort=${portnumber}" >> /mnt/hdd/raspiblitz.conf
else else
# update existing value # update existing value
sudo sed -i "s/^customPortLND=.*/customPortLND=${portnumber}/g" /mnt/hdd/raspiblitz.conf sudo sed -i "s/^lndPort=.*/lndPort=${portnumber}/g" /mnt/hdd/raspiblitz.conf
fi fi
# editing service file # editing service file
echo "editing /etc/systemd/system/lnd.service" echo "editing /etc/systemd/system/lnd.service"
sudo sed -i "s/^ExecStart=\/usr\/local\/bin\/lnd.*/ExecStart=\/usr\/local\/bin\/lnd --externalip=\${publicIP}:${portnumber}/g" /etc/systemd/system/lnd.service sudo sed -i "s/^ExecStart=\/usr\/local\/bin\/lnd.*/ExecStart=\/usr\/local\/bin\/lnd --externalip=\${publicIP}:\${lndPort}/g" /etc/systemd/system/lnd.service
# enable service again # enable service again
echo "enable service again" echo "enable service again"