better port conflict handling
This commit is contained in:
parent
104d77724a
commit
345da9ea6c
1 changed files with 15 additions and 15 deletions
|
|
@ -100,21 +100,21 @@ install_lnd() {
|
||||||
|
|
||||||
chmod 600 $USER_HOME/.lnd/lnd.conf
|
chmod 600 $USER_HOME/.lnd/lnd.conf
|
||||||
|
|
||||||
# Port conflict resolution for fresh installs
|
# Port conflict resolution.
|
||||||
if [ $lnd_status -eq 0 ]; then
|
local lnd_port=9735
|
||||||
local lnd_port=9735
|
if ! is_port_available $lnd_port; then
|
||||||
if ! is_port_available $lnd_port; then
|
# The port is occupied. We should intervene if our service is either in a failed state
|
||||||
if ! systemctl --user -q is-active lnd.service >/dev/null 2>&1; then
|
# or not active at all (which covers fresh installs and failure loops).
|
||||||
log "Port $lnd_port is in use by another process. Finding an alternative port."
|
if systemctl --user -q is-failed lnd.service 2>/dev/null || ! systemctl --user -q is-active lnd.service 2>/dev/null; then
|
||||||
lnd_port_new=$(find_available_port $lnd_port)
|
log "Port $lnd_port is occupied and LND service is not healthy. Attempting to resolve by finding a new port."
|
||||||
log "Configuring LND to use port $lnd_port_new."
|
lnd_port_new=$(find_available_port $lnd_port)
|
||||||
|
log "Configuring LND to use new port $lnd_port_new."
|
||||||
# Remove any existing listen entry and add the new one.
|
|
||||||
sed -i '/^listen=/d' $USER_HOME/.lnd/lnd.conf
|
sed -i '/^listen=/d' $USER_HOME/.lnd/lnd.conf
|
||||||
echo "listen=:$lnd_port_new" >> $USER_HOME/.lnd/lnd.conf
|
echo "listen=:$lnd_port_new" >> $USER_HOME/.lnd/lnd.conf
|
||||||
else
|
log "LND configuration updated. The service will be restarted by the installer."
|
||||||
log "Port $lnd_port is in use, but it seems to be by our own lnd service. No changes made."
|
else
|
||||||
fi
|
log "Port $lnd_port is in use by a healthy LND service (assumed to be our own). No changes will be made."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue