Report the configured listen address after install (#2243)

The final message always echoed $PORT, which falls back to the default when -p
is not passed. Existing service files are kept as they are, so a plain upgrade
on a host with a custom port reported that the agent runs on 45876 regardless
of the actual configuration.

Read the address from the active service file instead. LISTEN is checked before
PORT to match the agent's own precedence in GetAddress, and the value is read as
text so host:port and unix socket paths are reported as configured.
This commit is contained in:
Martin
2026-08-19 11:48:01 -04:00
committed by GitHub
parent ba90daf4d6
commit 946f2e6be1
+28 -1
View File
@@ -97,6 +97,30 @@ ensure_trailing_slash() {
fi
}
# Read the listen address from the active service configuration. Existing
# service files are kept as they are, so the configured address can differ from
# $PORT, which falls back to the default when -p is not passed. LISTEN is
# checked before PORT to match the agent's own precedence, and the value is read
# as text so host:port and unix socket paths survive.
configured_address() {
if is_alpine || is_openwrt; then
address_file=/etc/init.d/beszel-agent
elif is_freebsd; then
address_file="$AGENT_DIR/env"
else
address_file=/etc/systemd/system/beszel-agent.service
fi
[ -f "$address_file" ] || return 0
address_value=$(sed -n 's/.*LISTEN="\{0,1\}\([^"]*\)"\{0,1\}.*/\1/p' "$address_file" | head -n 1)
if [ -z "$address_value" ]; then
address_value=$(sed -n 's/.*PORT="\{0,1\}\([^"]*\)"\{0,1\}.*/\1/p' "$address_file" | head -n 1)
fi
printf '%s\n' "$address_value"
}
# Escape text for use in the replacement portion of a sed s command whose
# delimiter is |. This only escapes sed replacement metacharacters; quoting
# for the destination configuration syntax is handled separately.
@@ -1198,4 +1222,7 @@ EOF
fi
fi
printf "\n\033[32mBeszel Agent has been installed successfully! It is now running on $PORT.\033[0m\n"
RUNNING_ADDRESS=$(configured_address)
[ -n "$RUNNING_ADDRESS" ] || RUNNING_ADDRESS=$PORT
printf "\n\033[32mBeszel Agent has been installed successfully! It is now running on $RUNNING_ADDRESS.\033[0m\n"