Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c9288b2
Set the service up when a package or installer is installed (0.10.3)
James-Chapman Dec 1, 2026
6151cc1
Parse the ADR index without a backtracking regular expression
James-Chapman Dec 1, 2026
357c2c3
Address the CodeRabbit review of the service setup (17 findings)
James-Chapman Dec 1, 2026
31e1da9
Fix two ways the container smoke test could not pass
James-Chapman Dec 1, 2026
2f9602b
Tell an interrupted install from a finished one with a marker, not by…
James-Chapman Dec 1, 2026
c4724ee
Fix the smoke-script test on Linux: resolve sh before swapping PATH
James-Chapman Dec 1, 2026
c0f91be
Keep the install marker where the service user cannot reach it, and f…
James-Chapman Dec 1, 2026
6424a65
Close the server's firewall rules on removal and report setup failure…
James-Chapman Dec 1, 2026
576c503
Support Python 3.9 in the release tooling and explain FreeBSD smoke f…
James-Chapman Dec 1, 2026
7033a71
Merge main into feat/automatic-service-setup
James-Chapman Dec 1, 2026
8e9d8b9
Address the CodeRabbit review of the service setup
James-Chapman Dec 1, 2026
d18ee8f
Use onestart in the FreeBSD agent hint and tighten two installer mess…
James-Chapman Dec 1, 2026
48f8dd5
Take the config directory before setting its mode and finish the fire…
James-Chapman Dec 1, 2026
ad5a4ef
Leave a runtime-only firewalld port open on removal and correct the a…
James-Chapman Dec 1, 2026
71261a6
Record the running and permanent firewalld rules separately
James-Chapman Dec 1, 2026
9652b08
Keep only the firewall entries that could not be removed in the record
James-Chapman Dec 1, 2026
1045b09
Retry a refused firewall rule, and tighten the installer and smoke tests
James-Chapman Dec 1, 2026
a391173
Retry the firewall on its own, treat a failed firewalld query as unkn…
James-Chapman Dec 1, 2026
264f986
Retry only the firewall ports that failed and keep the list when no f…
James-Chapman Dec 1, 2026
93c3e2f
Skip the firewalld add when the query cannot say whether the port is …
James-Chapman Dec 1, 2026
44817c3
Track pending firewall work per port and per configuration
James-Chapman Dec 1, 2026
388c62a
Retry only the firewall that failed and tighten the removal advice an…
James-Chapman Dec 1, 2026
c92a51c
Say the Linux guide's manual steps also finish a Debian reinstall aft…
James-Chapman Dec 1, 2026
5a2f390
Keep each pending firewall entry until its own firewall resolves it
James-Chapman Dec 1, 2026
4848ec0
Stop owning a running firewalld rule once it is confirmed absent
James-Chapman Dec 1, 2026
8e0c1e8
Retry the nfpm and wrap downloads for about a minute
James-Chapman Dec 1, 2026
db578b5
End the FreeBSD job, keep upgraded services running, and keep a repla…
James-Chapman Dec 1, 2026
4695490
Handle config paths with spaces, verify the supervisor on removal, an…
James-Chapman Dec 1, 2026
2d85592
Record the owed start of a running service before replacing it
James-Chapman Dec 1, 2026
0fc3f34
Clear the owed start after a cancelled install by asking the service
James-Chapman Dec 1, 2026
2abdef8
Clear the owed start only when the service is positively running
James-Chapman Dec 1, 2026
18cedb5
Identify the FreeBSD supervisor by its retitled process name
James-Chapman Dec 2, 2026
b79b814
Escape the FreeBSD config path for rc.subr's evaluation, clear a stal…
James-Chapman Dec 2, 2026
c11cb16
Say what the prepare-failure cleanup actually guards
James-Chapman Dec 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@
# targets in LF-only files.
*.cmd text eol=crlf
*.bat text eol=crlf

# Files packaged for Linux and FreeBSD: a CRLF would break the interpreter line
# of the init scripts and the service definitions.
packaging/linux/openrc/* text eol=lf
packaging/freebsd/* text eol=lf
*.service text eol=lf
150 changes: 136 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ jobs:
- name: Test the release tooling
run: python3 scripts/release/release_tool_test.py

- name: Test the Linux and FreeBSD service setup
run: |
python3 scripts/release/service_setup_test.py
python3 scripts/release/freebsd_setup_test.py

- name: Read the version and build the Linux matrix
id: meta
run: |
Expand Down Expand Up @@ -140,12 +145,17 @@ jobs:
run: |
mkdir -p release-out
for component in server agent; do
# The maintainer scripts set the service up when the package is installed.
python3 scripts/release/release_tool.py package-scripts \
--component "$component" --format "$FORMAT" \
--out-dir "release-stage/scripts-$component"
python3 scripts/release/release_tool.py nfpm-config \
--catalogue packaging/linux/distros.json \
--component "$component" --distro "$DISTRO" --arch "$ARCH" \
--version "$VERSION" --release "$RELEASE" \
--stage-dir release-stage --dashboard-dir dashboard/dist \
--license-file LICENSE > "nfpm-$component.yaml"
--license-file LICENSE --packaging-dir packaging/linux \
--scripts-dir "release-stage/scripts-$component" > "nfpm-$component.yaml"
asset="$(python3 scripts/release/release_tool.py asset-name \
--component "$component" --platform "$DISTRO" --arch "$ARCH" --ext "$EXT")"
nfpm package --config "nfpm-$component.yaml" --packager "$FORMAT" \
Expand All @@ -162,7 +172,8 @@ jobs:
--volume "$PWD/release-out:/pkgs:ro" \
--volume "$PWD/scripts/release:/release:ro" \
--env INSTALL_CMD --env EXPECTED_VERSION="$VERSION" \
"$IMAGE" sh /release/smoke-install.sh
--env THEWATCHER_SERVER=localhost --env ENROLLMENT_TOKEN=smoke-token \
"$IMAGE" sh -c 'sh /release/smoke-install.sh && sh /release/smoke-service.sh'

- uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -207,12 +218,9 @@ jobs:
Set-Content -Path $path -Value 'stand-in'
}

# The runner image ships Inno Setup; install it if that ever changes.
$iscc = "${env:ProgramFiles(x86)}\Inno Setup 6\ISCC.exe"
if (-not (Test-Path $iscc)) {
choco install innosetup --no-progress -y
if ($LASTEXITCODE -ne 0) { throw 'choco install innosetup failed' }
}
# The runner image only ships the previous major version (6). The installers
# are built with 7, installed from a pinned, verified download (docs/adr/0006).
$iscc = & scripts/release/install-inno-setup.ps1 -Destination "$env:RUNNER_TEMP\InnoSetup"

$env:THEWATCHER_VERSION = $env:VERSION
foreach ($component in 'server', 'agent') {
Expand Down Expand Up @@ -283,12 +291,9 @@ jobs:
New-Item -ItemType Directory -Force release-stage/crt | Out-Null
Copy-Item "$($crt.FullName)/*.dll" release-stage/crt

# The runner image may not ship Inno Setup.
$iscc = "${env:ProgramFiles(x86)}\Inno Setup 6\ISCC.exe"
if (-not (Test-Path $iscc)) {
choco install innosetup --no-progress -y
if ($LASTEXITCODE -ne 0) { throw 'choco install innosetup failed' }
}
# Inno Setup 7 from a pinned, verified download (the image ships only 6;
# docs/adr/0006).
$iscc = & scripts/release/install-inno-setup.ps1 -Destination "$env:RUNNER_TEMP\InnoSetup"

# TheWatcher.iss reads the version and the component from these
# variables; it refuses to compile without a component.
Expand All @@ -304,6 +309,121 @@ jobs:
}
Get-ChildItem release-out

# The installers must leave working services behind. Install them for real
# on the runner (an administrator), check the result, upgrade, then
# uninstall. Nothing here publishes anything.
- name: Install, upgrade and uninstall the installers
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$configDir = Join-Path $env:ProgramData 'TheWatcher'
$rule = 'TheWatcher server (agents)'
$uninstallKey = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall'
$appIds = @{ server = '{B94E273C-BD27-4184-82A2-8F6726F6DE2E}'; agent = '{0EDA80FF-F84A-44C5-B376-F3017E8EE1E6}' }

function Assert-That([bool]$condition, [string]$message) {
if (-not $condition) { throw "FAIL: $message" }
Write-Host "ok $message"
}

# Runs one installer silently and fails with its setup log on a non-zero exit.
function Install-Product([string]$name, [string[]]$extra = @()) {
$log = Join-Path $env:RUNNER_TEMP "$name-setup.log"
$installer = (Resolve-Path "release-out/thewatcher-$name-windows-x86_64.exe").Path
$arguments = @('/VERYSILENT', '/SUPPRESSMSGBOXES', '/NORESTART', "/LOG=$log") + $extra
$process = Start-Process -FilePath $installer -ArgumentList $arguments -Wait -PassThru
if ($process.ExitCode -ne 0) {
if (Test-Path $log) { Get-Content $log | Select-Object -Last 80 }
throw "FAIL: the $name installer exited with $($process.ExitCode)"
}
}

function Uninstall-Product([string]$name) {
$entry = Get-ItemProperty (Join-Path $uninstallKey "$($appIds[$name])_is1")
$uninstaller = $entry.UninstallString.Trim('"')
$process = Start-Process -FilePath $uninstaller -ArgumentList '/VERYSILENT', '/SUPPRESSMSGBOXES', '/NORESTART' -Wait -PassThru
Assert-That ($process.ExitCode -eq 0) "the $name uninstaller exits 0"
}

function Config-Lines([string]$file) { Get-Content (Join-Path $configDir $file) }

# ── Server: first install ────────────────────────────────────────────
Install-Product 'server'
Assert-That ((Get-Service TheWatcherServer).Status -eq 'Running') 'the server service is running after a first install'
$server = Config-Lines 'TheWatcherServer.conf'
Assert-That ($server -contains 'API_HOST=127.0.0.1') 'the server API listens on loopback only'
Assert-That (($server | Where-Object { $_ -match '^ENROLLMENT_TOKEN=[0-9a-f]{48}$' }).Count -eq 1) 'the server config has a generated enrollment token'
Assert-That (($server | Where-Object { $_ -match '^SERVER_SECRET_KEY=.{40}$' }).Count -eq 1) 'the server config has a CURVE secret key'
Assert-That ((sc.exe qfailure TheWatcherServer | Out-String) -match 'RESTART') 'the server service restarts on failure'

$firewall = Get-NetFirewallRule -DisplayName $rule
Assert-That (@($firewall).Count -eq 1) 'there is one firewall rule for the agents'
Assert-That ("$($firewall.Profile)" -eq 'Domain, Private') 'the rule covers only the Domain and Private profiles'
Assert-That ("$($firewall.Direction)" -eq 'Inbound' -and "$($firewall.Action)" -eq 'Allow') 'the rule allows inbound traffic'
$ports = @(($firewall | Get-NetFirewallPortFilter).LocalPort) | Sort-Object
Assert-That (($ports -join ',') -eq '5555,5556') 'the rule opens TCP 5555 and 5556'
$program = ($firewall | Get-NetFirewallApplicationFilter).Program
Assert-That ($program -like '*\TheWatcherServer.exe') 'the rule is tied to the server executable'

# ── Server: upgrade over itself ──────────────────────────────────────
$before = (Get-FileHash (Join-Path $configDir 'TheWatcherServer.conf')).Hash
Install-Product 'server'
Assert-That ((Get-Service TheWatcherServer).Status -eq 'Running') 'the server service is running again after an upgrade'
Assert-That ((Get-FileHash (Join-Path $configDir 'TheWatcherServer.conf')).Hash -eq $before) 'an upgrade leaves the server config unchanged'
Assert-That (@(Get-NetFirewallRule -DisplayName $rule).Count -eq 1) 'an upgrade does not add a second firewall rule'

# ── Server: a replacement that stopped half way ─────────────────────
# RegisterService says to close services.msc and run the installer again when the old
# service is still marked for deletion. By then the service is gone, and the run must
# still count as an upgrade. Make that state: the marker the installer leaves, no
# service, the rule narrowed by the administrator, and the service stopped.
Stop-Service TheWatcherServer
sc.exe delete TheWatcherServer | Out-Null
Assert-That ($null -eq (Get-Service TheWatcherServer -ErrorAction SilentlyContinue)) 'the service is gone before the installer runs again'
Set-Content -Path (Join-Path $configDir 'TheWatcherServer.replacing') -Value 'replacing'
Set-NetFirewallRule -DisplayName $rule -RemoteAddress '10.0.0.0/8'
$narrowed = "$((Get-NetFirewallRule -DisplayName $rule | Get-NetFirewallAddressFilter).RemoteAddress)"
Assert-That ($narrowed -ne 'Any') 'the test narrowed the rule'
Install-Product 'server'
Assert-That ($null -ne (Get-Service TheWatcherServer -ErrorAction SilentlyContinue)) 'the service is registered again'
Assert-That ((Get-Service TheWatcherServer).Status -eq 'Stopped') 'an interrupted replacement does not start a service the administrator had stopped'
$after = "$((Get-NetFirewallRule -DisplayName $rule | Get-NetFirewallAddressFilter).RemoteAddress)"
Assert-That ($after -eq $narrowed) 'an interrupted replacement keeps the firewall rule the administrator narrowed'
Assert-That (-not (Test-Path (Join-Path $configDir 'TheWatcherServer.replacing'))) 'the marker is removed once the service is registered again'
Start-Service TheWatcherServer

# ── Agent: no server address ─────────────────────────────────────────
Install-Product 'agent'
$agent = Get-Service TheWatcherAgent
Assert-That ($agent.Status -eq 'Stopped') 'an agent without a server address is not started'
Assert-That ($agent.StartType -eq 'Manual') 'an agent without a server address does not start at boot'
Assert-That (-not (Test-Path (Join-Path $configDir 'TheWatcherAgent.conf'))) 'no agent config is made up without an address'

# ── Agent: finished later with /SERVER= ──────────────────────────────
# The token goes in the environment, not in a switch: Setup's /LOG= writes its
# whole command line to the log. It has spaces and a trailing backslash on
# purpose; the installer must hand it to the agent exactly as given.
$token = 'correct horse battery staple\'
$env:ENROLLMENT_TOKEN = $token
Install-Product 'agent' @('/SERVER=localhost')
Remove-Item Env:ENROLLMENT_TOKEN
$agent = Get-Service TheWatcherAgent
Assert-That ($agent.Status -eq 'Running') 'the agent runs once it is given a server address'
Assert-That ($agent.StartType -eq 'Automatic') 'the agent starts at boot once it is configured'
$agentConf = Config-Lines 'TheWatcherAgent.conf'
Assert-That ($agentConf -contains 'THEWATCHER_SERVER=localhost') 'the agent config has the server address'
Assert-That ($agentConf -contains "ENROLLMENT_TOKEN=$token") 'the agent config has the enrollment token exactly as given'
$setupLog = Get-Content (Join-Path $env:RUNNER_TEMP 'agent-setup.log') -Raw
Assert-That (-not $setupLog.Contains('horse battery')) 'the setup log does not contain the enrollment token'

# ── Uninstall ────────────────────────────────────────────────────────
Uninstall-Product 'agent'
Uninstall-Product 'server'
Assert-That ($null -eq (Get-Service TheWatcherServer -ErrorAction SilentlyContinue)) 'the server service is removed'
Assert-That ($null -eq (Get-Service TheWatcherAgent -ErrorAction SilentlyContinue)) 'the agent service is removed'
Assert-That ($null -eq (Get-NetFirewallRule -DisplayName $rule -ErrorAction SilentlyContinue)) 'the firewall rule is removed'
Assert-That (Test-Path (Join-Path $configDir 'TheWatcherServer.conf')) 'uninstalling keeps the server config and its keys'

- uses: actions/upload-artifact@v4
with:
name: release-windows
Expand Down Expand Up @@ -354,6 +474,8 @@ jobs:
set -e
sh ./meson-build-bsd.sh
sh scripts/release/freebsd-package.sh
# Installs the packages and checks that the services come up.
sh scripts/release/freebsd-smoke.sh

- uses: actions/upload-artifact@v4
with:
Expand Down
Loading
Loading