Skip to content

Commit 18b0323

Browse files
committed
Add agent-id support to host agent installers (Related to #721)
1 parent 5160979 commit 18b0323

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

docs/HOST_AGENT.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,18 @@ Start-Service -Name PulseHostAgent
201201

202202
Run `pulse-host-agent --help` for the full list.
203203

204+
## Avoiding ID collisions
205+
206+
Pulse keys hosts on the identifier supplied by the agent (machine-id by default). Cloned systems frequently share `/etc/machine-id`, which makes Pulse alternate a single row between multiple machines. Keep the ID unique by regenerating the machine-id on each clone or by providing an explicit `--agent-id`/`PULSE_AGENT_ID` when installing:
207+
208+
```bash
209+
sudo rm /etc/machine-id /var/lib/dbus/machine-id
210+
sudo systemd-machine-id-setup
211+
sudo systemctl restart pulse-host-agent
212+
```
213+
214+
Re-running the installer with `--agent-id <unique-name>` achieves the same result if regenerating the machine-id is undesirable.
215+
204216
## Viewing Hosts
205217

206218
- **Settings → Agents → Host agents** lists every reporting host and provides ready-made install commands.

scripts/install-host-agent.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ param(
1111
[string]$PulseUrl = $env:PULSE_URL,
1212
[string]$Token = $env:PULSE_TOKEN,
1313
[string]$Interval = $env:PULSE_INTERVAL,
14+
[string]$AgentId = $env:PULSE_AGENT_ID,
1415
[string]$InstallPath = "C:\Program Files\Pulse",
1516
[string]$Arch = $env:PULSE_ARCH,
1617
[switch]$NoService
@@ -251,6 +252,7 @@ if (-not $Interval) {
251252
PulseInfo "Configuration:"
252253
Write-Host " Pulse URL: $PulseUrl"
253254
Write-Host " Token: $(if ($Token) { '***' + $Token.Substring([Math]::Max(0, $Token.Length - 4)) } else { 'none' })"
255+
Write-Host " Agent ID: $(if ($AgentId) { $AgentId } else { 'machine-id (default)' })"
254256
Write-Host " Interval: $Interval"
255257
Write-Host " Install Path: $InstallPath"
256258
if ($Arch) {
@@ -381,6 +383,9 @@ try {
381383
if ($Token) {
382384
$agentArgs += @("--token", "`"$Token`"")
383385
}
386+
if ($AgentId) {
387+
$agentArgs += @("--agent-id", "`"$AgentId`"")
388+
}
384389
$serviceBinaryPath = "`"$agentPath`" $($agentArgs -join ' ')"
385390
$manualCommand = "& `"$agentPath`" $($agentArgs -join ' ')"
386391
} catch {
@@ -397,6 +402,9 @@ $config = @{
397402
if ($Token) {
398403
$config.token = $Token
399404
}
405+
if ($AgentId) {
406+
$config.agentId = $AgentId
407+
}
400408

401409
$config | ConvertTo-Json | Set-Content $configPath
402410
PulseSuccess "Created configuration at $configPath"

scripts/install-host-agent.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ KEYCHAIN_ENABLED=true
7171
KEYCHAIN_OPT_OUT=false
7272
KEYCHAIN_OPT_OUT_REASON=""
7373
USE_KEYCHAIN=false
74+
AGENT_ID="${PULSE_AGENT_ID:-}"
7475

7576
while [[ $# -gt 0 ]]; do
7677
case "$1" in
@@ -86,6 +87,10 @@ while [[ $# -gt 0 ]]; do
8687
INTERVAL="$2"
8788
shift 2
8889
;;
90+
--agent-id)
91+
AGENT_ID="$2"
92+
shift 2
93+
;;
8994
--platform)
9095
PLATFORM="$2"
9196
shift 2
@@ -162,9 +167,10 @@ fi
162167

163168
if [[ -z "$PULSE_URL" ]]; then
164169
log_error "Pulse URL is required"
165-
echo "Usage: $0 --url <pulse-url> --token <api-token> [--interval 30s] [--platform linux|darwin|windows] [--force] [--no-keychain]"
170+
echo "Usage: $0 --url <pulse-url> --token <api-token> [--interval 30s] [--agent-id <id>] [--platform linux|darwin|windows] [--force] [--no-keychain]"
166171
echo ""
167172
echo " --force Skip interactive prompts and accept secure defaults (including Keychain storage)."
173+
echo " --agent-id Override the identifier used to deduplicate hosts (defaults to machine-id)."
168174
echo " --no-keychain Disable Keychain storage and embed the token in the launch agent plist instead."
169175
exit 1
170176
fi
@@ -234,6 +240,11 @@ if [[ -n "$PULSE_TOKEN" ]]; then
234240
else
235241
echo " Token: none"
236242
fi
243+
if [[ -n "$AGENT_ID" ]]; then
244+
echo " Agent ID: $AGENT_ID"
245+
else
246+
echo " Agent ID: machine-id (default)"
247+
fi
237248
echo " Interval: $INTERVAL"
238249
echo " Platform: $PLATFORM/$ARCH"
239250
echo ""
@@ -406,6 +417,9 @@ if [[ -n "$PULSE_TOKEN" ]]; then
406417
AGENT_CMD="$AGENT_CMD --token $PULSE_TOKEN"
407418
fi
408419
AGENT_CMD="$AGENT_CMD --interval $INTERVAL"
420+
if [[ -n "$AGENT_ID" ]]; then
421+
AGENT_CMD="$AGENT_CMD --agent-id $AGENT_ID"
422+
fi
409423
MANUAL_START_CMD="$AGENT_CMD"
410424
MANUAL_START_WRAPPED="nohup $MANUAL_START_CMD >$LINUX_LOG_FILE 2>&1 &"
411425

@@ -529,6 +543,12 @@ elif [[ "$PLATFORM" == "darwin" ]] && command -v launchctl &> /dev/null; then
529543
USE_KEYCHAIN=false
530544
fi
531545

546+
LAUNCHD_AGENT_ID_ARGS=""
547+
if [[ -n "$AGENT_ID" ]]; then
548+
LAUNCHD_AGENT_ID_ARGS=" <string>--agent-id</string>
549+
<string>$AGENT_ID</string>"
550+
fi
551+
532552
# Create wrapper script if using Keychain
533553
if [[ "$USE_KEYCHAIN" == true ]]; then
534554
WRAPPER_SCRIPT="/usr/local/bin/pulse-host-agent-wrapper.sh"
@@ -588,6 +608,7 @@ WRAPPER_EOF
588608
<string>$PULSE_URL</string>
589609
<string>--interval</string>
590610
<string>$INTERVAL</string>
611+
$LAUNCHD_AGENT_ID_ARGS
591612
</array>
592613
<key>RunAtLoad</key>
593614
<true/>
@@ -619,6 +640,7 @@ EOF
619640
<string>$PULSE_TOKEN</string>
620641
<string>--interval</string>
621642
<string>$INTERVAL</string>
643+
$LAUNCHD_AGENT_ID_ARGS
622644
</array>
623645
<key>RunAtLoad</key>
624646
<true/>

0 commit comments

Comments
 (0)