Skip to content

Lightweight server monitoring with historical data, docker stats, and alerts.

Report the configured listen address after install (#2243)

Martin946f2e6be131
diff --git a/supplemental/scripts/install-agent.sh b/supplemental/scripts/install-agent.sh
index 8398d0ebd..b7907b1c6 100755
--- a/supplemental/scripts/install-agent.sh
+++ b/supplemental/scripts/install-agent.sh
@@ -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"