Initial import: nasmon health monitor, split out of home_nas

Go service (nasmon/) plus nfpm packaging (packaging/), carried over from
the home_nas monorepo. Adds rpm packaging alongside the existing deb
build (Fedora/RHEL/Rocky dependency names via nfpm overrides, per-format
systemd unit path, dpkg+rpm-compatible maintainer scripts) and a Gitea
Actions workflow that builds both formats on every push.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-19 10:24:34 +03:00
co-authored by Claude Sonnet 5
commit 09159a5f31
61 changed files with 7882 additions and 0 deletions
+87
View File
@@ -0,0 +1,87 @@
<#
.SYNOPSIS
Builds the nasmon binary (linux/amd64, static) and packs it into a .deb and .rpm with nfpm.
Output: dist\nasmon_<version>_amd64.deb and dist\nasmon-<version>.<arch>.rpm
One-time setup:
winget install GoLang.Go
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest
.EXAMPLE
.\build.ps1 # version from git tag, or 0.1.0+<timestamp>
.\build.ps1 -Version 0.2.0
.\build.ps1 -Test # run go vet + go test first
#>
[CmdletBinding()]
param(
[string]$Version,
[switch]$Test
)
$ErrorActionPreference = "Stop"
$root = $PSScriptRoot
$src = $root
$dist = Join-Path $root "dist"
# tools: go and nfpm may live outside PATH in a fresh shell
$env:Path = "$env:Path;C:\Program Files\Go\bin;$env:USERPROFILE\go\bin"
foreach ($tool in "go", "nfpm") {
if (-not (Get-Command $tool -ErrorAction SilentlyContinue)) {
throw "$tool not found - see the setup notes at the top of build.ps1"
}
}
if (-not $Version) {
$Version = $null
if (Get-Command git -ErrorAction SilentlyContinue) {
Push-Location $root
try { $tag = git describe --tags --always --dirty 2>$null } catch { $tag = $null }
Pop-Location
if ($tag -and $tag -match '^v?(\d+\.\d+\.\d+)(-(\d+)-g([0-9a-f]+))?(-dirty)?$') {
$Version = $Matches[1]
if ($Matches[3]) { $Version += "+git$($Matches[3]).$($Matches[4])" }
if ($Matches[5]) { $Version += ".dirty" }
}
}
if (-not $Version) { $Version = "0.1.0+" + (Get-Date -Format "yyyyMMdd.HHmm") }
}
New-Item -ItemType Directory -Force $dist | Out-Null
if ($Test) {
Write-Host "==> go vet / go test" -ForegroundColor Green
Push-Location $src
try {
go vet ./...; if ($LASTEXITCODE -ne 0) { throw "go vet failed" }
go test ./...; if ($LASTEXITCODE -ne 0) { throw "go test failed" }
} finally { Pop-Location }
}
Write-Host "==> Building nasmon $Version (linux/amd64)" -ForegroundColor Green
$env:GOOS = "linux"; $env:GOARCH = "amd64"; $env:CGO_ENABLED = "0"
Push-Location $src
try {
go build -trimpath -ldflags "-s -w -X main.version=$Version" -o (Join-Path $dist "nasmon") ./cmd/nasmon
if ($LASTEXITCODE -ne 0) { throw "go build failed" }
} finally {
Pop-Location
Remove-Item Env:GOOS, Env:GOARCH, Env:CGO_ENABLED -ErrorAction SilentlyContinue
}
Write-Host "==> Packaging .deb" -ForegroundColor Green
Get-ChildItem $dist -Filter "nasmon_*.deb" | Remove-Item -Force
$env:NASMON_VERSION = $Version
Push-Location (Join-Path $root "packaging")
try {
nfpm package -f nfpm.yaml -p deb -t $dist
if ($LASTEXITCODE -ne 0) { throw "nfpm deb failed" }
Write-Host "==> Packaging .rpm" -ForegroundColor Green
Get-ChildItem $dist -Filter "nasmon-*.rpm" | Remove-Item -Force
nfpm package -f nfpm.yaml -p rpm -t $dist
if ($LASTEXITCODE -ne 0) { throw "nfpm rpm failed" }
} finally { Pop-Location }
foreach ($pkg in (Get-ChildItem $dist -Filter "nasmon*" -Include "*.deb", "*.rpm")) {
Write-Host "==> $($pkg.FullName) ($([math]::Round($pkg.Length / 1MB, 1)) MB)" -ForegroundColor Green
}