Add --agent-id parameter to unified agent installers
The unified installer was missing --agent-id support that existed in the legacy host-agent installer. This parameter allows users to specify a custom agent identifier instead of using auto-generated IDs. Updated both install.sh (Linux/macOS/Synology/Unraid) and install.ps1 (Windows) to accept --agent-id and pass it through to the agent binary. Related to #772
This commit is contained in:
parent
1b866598c4
commit
1fd439237d
2 changed files with 13 additions and 1 deletions
|
|
@ -10,7 +10,8 @@ param (
|
||||||
[bool]$EnableHost = $true,
|
[bool]$EnableHost = $true,
|
||||||
[bool]$EnableDocker = $false,
|
[bool]$EnableDocker = $false,
|
||||||
[bool]$Insecure = $false,
|
[bool]$Insecure = $false,
|
||||||
[bool]$Uninstall = $false
|
[bool]$Uninstall = $false,
|
||||||
|
[string]$AgentId = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
$ErrorActionPreference = "Stop"
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
@ -292,6 +293,7 @@ $ServiceArgs = @(
|
||||||
if ($EnableHost) { $ServiceArgs += "--enable-host" }
|
if ($EnableHost) { $ServiceArgs += "--enable-host" }
|
||||||
if ($EnableDocker) { $ServiceArgs += "--enable-docker" }
|
if ($EnableDocker) { $ServiceArgs += "--enable-docker" }
|
||||||
if ($Insecure) { $ServiceArgs += "--insecure" }
|
if ($Insecure) { $ServiceArgs += "--insecure" }
|
||||||
|
if (-not [string]::IsNullOrWhiteSpace($AgentId)) { $ServiceArgs += @("--agent-id", "`"$AgentId`"") }
|
||||||
|
|
||||||
$BinPath = "`"$DestPath`" $($ServiceArgs -join ' ')"
|
$BinPath = "`"$DestPath`" $($ServiceArgs -join ' ')"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
# --enable-host Enable host metrics (default: true)
|
# --enable-host Enable host metrics (default: true)
|
||||||
# --enable-docker Enable docker metrics (default: false)
|
# --enable-docker Enable docker metrics (default: false)
|
||||||
# --interval <dur> Reporting interval (default: 30s)
|
# --interval <dur> Reporting interval (default: 30s)
|
||||||
|
# --agent-id <id> Custom agent identifier (default: auto-generated)
|
||||||
# --uninstall Remove the agent
|
# --uninstall Remove the agent
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
@ -48,6 +49,7 @@ ENABLE_HOST="true"
|
||||||
ENABLE_DOCKER="false"
|
ENABLE_DOCKER="false"
|
||||||
UNINSTALL="false"
|
UNINSTALL="false"
|
||||||
INSECURE="false"
|
INSECURE="false"
|
||||||
|
AGENT_ID=""
|
||||||
|
|
||||||
# --- Helper Functions ---
|
# --- Helper Functions ---
|
||||||
log_info() { printf "[INFO] %s\n" "$1"; }
|
log_info() { printf "[INFO] %s\n" "$1"; }
|
||||||
|
|
@ -70,6 +72,7 @@ build_exec_args() {
|
||||||
if [[ "$ENABLE_HOST" == "true" ]]; then EXEC_ARGS="$EXEC_ARGS --enable-host"; fi
|
if [[ "$ENABLE_HOST" == "true" ]]; then EXEC_ARGS="$EXEC_ARGS --enable-host"; fi
|
||||||
if [[ "$ENABLE_DOCKER" == "true" ]]; then EXEC_ARGS="$EXEC_ARGS --enable-docker"; fi
|
if [[ "$ENABLE_DOCKER" == "true" ]]; then EXEC_ARGS="$EXEC_ARGS --enable-docker"; fi
|
||||||
if [[ "$INSECURE" == "true" ]]; then EXEC_ARGS="$EXEC_ARGS --insecure"; fi
|
if [[ "$INSECURE" == "true" ]]; then EXEC_ARGS="$EXEC_ARGS --insecure"; fi
|
||||||
|
if [[ -n "$AGENT_ID" ]]; then EXEC_ARGS="$EXEC_ARGS --agent-id ${AGENT_ID}"; fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Build exec args as array for direct execution (proper quoting)
|
# Build exec args as array for direct execution (proper quoting)
|
||||||
|
|
@ -79,6 +82,7 @@ build_exec_args_array() {
|
||||||
if [[ "$ENABLE_HOST" == "true" ]]; then EXEC_ARGS_ARRAY+=(--enable-host); fi
|
if [[ "$ENABLE_HOST" == "true" ]]; then EXEC_ARGS_ARRAY+=(--enable-host); fi
|
||||||
if [[ "$ENABLE_DOCKER" == "true" ]]; then EXEC_ARGS_ARRAY+=(--enable-docker); fi
|
if [[ "$ENABLE_DOCKER" == "true" ]]; then EXEC_ARGS_ARRAY+=(--enable-docker); fi
|
||||||
if [[ "$INSECURE" == "true" ]]; then EXEC_ARGS_ARRAY+=(--insecure); fi
|
if [[ "$INSECURE" == "true" ]]; then EXEC_ARGS_ARRAY+=(--insecure); fi
|
||||||
|
if [[ -n "$AGENT_ID" ]]; then EXEC_ARGS_ARRAY+=(--agent-id "$AGENT_ID"); fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- Parse Arguments ---
|
# --- Parse Arguments ---
|
||||||
|
|
@ -93,6 +97,7 @@ while [[ $# -gt 0 ]]; do
|
||||||
--disable-docker) ENABLE_DOCKER="false"; shift ;;
|
--disable-docker) ENABLE_DOCKER="false"; shift ;;
|
||||||
--insecure) INSECURE="true"; shift ;;
|
--insecure) INSECURE="true"; shift ;;
|
||||||
--uninstall) UNINSTALL="true"; shift ;;
|
--uninstall) UNINSTALL="true"; shift ;;
|
||||||
|
--agent-id) AGENT_ID="$2"; shift 2 ;;
|
||||||
*) fail "Unknown argument: $1" ;;
|
*) fail "Unknown argument: $1" ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
@ -305,6 +310,11 @@ if [[ "$OS" == "darwin" ]]; then
|
||||||
PLIST_ARGS="${PLIST_ARGS}
|
PLIST_ARGS="${PLIST_ARGS}
|
||||||
<string>--insecure</string>"
|
<string>--insecure</string>"
|
||||||
fi
|
fi
|
||||||
|
if [[ -n "$AGENT_ID" ]]; then
|
||||||
|
PLIST_ARGS="${PLIST_ARGS}
|
||||||
|
<string>--agent-id</string>
|
||||||
|
<string>${AGENT_ID}</string>"
|
||||||
|
fi
|
||||||
|
|
||||||
cat > "$PLIST" <<EOF
|
cat > "$PLIST" <<EOF
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue