Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix(windows): actually keep the configuration an uninstall promises to keep

shukieshahf54062fc2f8d
diff --git a/packaging/windows/beacon.wxs b/packaging/windows/beacon.wxs
index 4a15c4bc..657152bf 100644
--- a/packaging/windows/beacon.wxs
+++ b/packaging/windows/beacon.wxs
@@ -114,7 +114,16 @@
<InstallExecuteSequence>
<!-- NOT REMOVE, so this runs on a first install and on an upgrade, but not during removal. -->
<Custom Action="BeaconInstallEndpoint" After="InstallFiles" Condition="NOT REMOVE" />
- <Custom Action="BeaconUninstallEndpoint" Before="RemoveFiles" Condition="REMOVE=&quot;ALL&quot;" />
+ <!--
+ Skipped during an upgrade, and the reason is the one the Linux preremove script documents at
+ length. MajorUpgrade removes the older product as part of the same transaction, which would
+ otherwise run this action and tear down the endpoint the upgrade is about to reinstall — work
+ that is at best pointless and at worst leaves a window with no running collector.
+ UPGRADINGPRODUCTCODE is set only during that removal half, which makes it the MSI equivalent
+ of dpkg's "upgrade" argument and rpm's remaining-version count.
+ -->
+ <Custom Action="BeaconUninstallEndpoint" Before="RemoveFiles"
+ Condition="REMOVE=&quot;ALL&quot; AND NOT UPGRADINGPRODUCTCODE" />
</InstallExecuteSequence>
</Package>
</Wix>
diff --git a/packaging/windows/uninstall-endpoint.ps1 b/packaging/windows/uninstall-endpoint.ps1
index e53ac2d1..62b9610a 100644
--- a/packaging/windows/uninstall-endpoint.ps1
+++ b/packaging/windows/uninstall-endpoint.ps1
@@ -6,6 +6,12 @@
# follows: removing the product should not destroy an operator's settings or the telemetry they have
# collected, because an uninstall is often the first half of an upgrade or a reinstall. Set
# BEACON_PURGE=1 to remove them, which is the deliberate, separate act.
+#
+# Keeping them takes more than passing --keep-config, and the flag's name is genuinely misleading:
+# it governs *harness* telemetry settings, not Beacon's own. `endpoint uninstall` removes everything
+# recorded in its install manifest -- which includes config.json and otelcol.yaml -- unconditionally,
+# because that is what uninstall means at the CLI level. So the files are set aside and put back, the
+# same stash-and-restore packaging/linux/nfpm/preremove.sh performs and for the same reason.
[CmdletBinding()]
param()
@@ -30,14 +36,31 @@ if (-not (Test-Path -LiteralPath $beaconBin)) {
exit 0
}
-$uninstallArgs = @('endpoint', 'uninstall', '--system')
+$configDir = Join-Path $env:ProgramData 'Beacon\Endpoint'
+$retained = @('config.json', 'otelcol.yaml')
+
+$stash = $null
if ($purge -ne '1') {
- $uninstallArgs += @('--keep-logs', '--keep-config')
+ $stash = Join-Path ([System.IO.Path]::GetTempPath()) ("beacon-uninstall-" + [Guid]::NewGuid().ToString('N'))
+ New-Item -ItemType Directory -Force -Path $stash | Out-Null
+ foreach ($name in $retained) {
+ $source = Join-Path $configDir $name
+ if (Test-Path -LiteralPath $source) {
+ Copy-Item -LiteralPath $source -Destination (Join-Path $stash $name) -Force
+ }
+ }
Write-Output "beacon: removing the endpoint, keeping configuration and logs (set BEACON_PURGE=1 to remove them)"
} else {
Write-Output "beacon: removing the endpoint, configuration and logs"
}
+$uninstallArgs = @('endpoint', 'uninstall', '--system')
+if ($purge -ne '1') {
+ # --keep-logs does what its name says. --keep-config is passed for the harness settings it does
+ # govern; the stash above is what actually preserves Beacon's own configuration.
+ $uninstallArgs += @('--keep-logs', '--keep-config')
+}
+
& $beaconBin @uninstallArgs
if ($LASTEXITCODE -ne 0) {
# Reported, not thrown. The service and its registration are what matter here, and `endpoint
@@ -46,4 +69,29 @@ if ($LASTEXITCODE -ne 0) {
Write-Warning "beacon: endpoint uninstall exited $LASTEXITCODE; check 'beacon endpoint status --system'"
}
+if ($null -ne $stash) {
+ try {
+ $restored = 0
+ foreach ($name in $retained) {
+ $saved = Join-Path $stash $name
+ if (Test-Path -LiteralPath $saved) {
+ New-Item -ItemType Directory -Force -Path $configDir | Out-Null
+ Copy-Item -LiteralPath $saved -Destination (Join-Path $configDir $name) -Force
+ $restored++
+ }
+ }
+ if ($restored -gt 0) {
+ Write-Output "beacon: restored $restored configuration file(s) to $configDir"
+ }
+ } finally {
+ Remove-Item -LiteralPath $stash -Recurse -Force -ErrorAction SilentlyContinue
+ }
+} else {
+ # The purge half of the contract, matching postremove.sh: what was deliberately kept above is
+ # exactly what a purge is for removing. One recursive delete covers the logs too, because the
+ # system log directory lives under this one on Windows -- there is no /var/log equivalent to
+ # remove separately.
+ Remove-Item -LiteralPath $configDir -Recurse -Force -ErrorAction SilentlyContinue
+}
+
Write-Output "beacon: endpoint removed"