2 Commits

Author SHA1 Message Date
urania dbce9aa56e fix: minor changes on update
build-and-release / release (push) Successful in 2m5s
2026-06-22 19:15:06 +02:00
urania 60b9fbc42c fix: cpu info
build-and-release / release (push) Successful in 2m4s
2026-06-22 18:54:50 +02:00
4 changed files with 28 additions and 4 deletions
+1
View File
@@ -232,6 +232,7 @@ func runServer() {
meta.Register(api, mods) meta.Register(api, mods)
meta.RegisterHealth(api, sessions) meta.RegisterHealth(api, sessions)
meta.RegisterWhoami(api, sessions, roles, mods) meta.RegisterWhoami(api, sessions, roles, mods)
meta.ConfigPath = configPath
meta.RegisterUpdate(api) meta.RegisterUpdate(api)
auth.RegisterLogin(api, sessions, auditStore, cfg.SecureCookie()) auth.RegisterLogin(api, sessions, auditStore, cfg.SecureCookie())
+15 -1
View File
@@ -6,11 +6,16 @@ import (
"os/exec" "os/exec"
"syscall" "syscall"
"nadir/internal/config"
"nadir/internal/oscmd" "nadir/internal/oscmd"
"github.com/danielgtaylor/huma/v2" "github.com/danielgtaylor/huma/v2"
) )
// ConfigPath is set at startup so the update handler can re-load config and
// surface release_repo / parse errors to the caller instead of only stderr.
var ConfigPath string
// RegisterUpdate wires POST /api/meta/update. It runs the equivalent of // RegisterUpdate wires POST /api/meta/update. It runs the equivalent of
// `sudo nadir update` in a detached session and returns 202 immediately; the // `sudo nadir update` in a detached session and returns 202 immediately; the
// systemctl restart that ends the updater drops in-flight connections, so the // systemctl restart that ends the updater drops in-flight connections, so the
@@ -28,9 +33,18 @@ func RegisterUpdate(api huma.API) {
Description: "Equivalent to running `sudo nadir update` on the host: queries server.release_repo for the latest release, downloads the binary matching the host's architecture, atomically replaces the running binary, and restarts the systemd unit. Returns 202 immediately; the service restart drops in-flight connections, so poll /api/health to confirm the new version is up. Requires the wildcard admin role.", Description: "Equivalent to running `sudo nadir update` on the host: queries server.release_repo for the latest release, downloads the binary matching the host's architecture, atomically replaces the running binary, and restarts the systemd unit. Returns 202 immediately; the service restart drops in-flight connections, so poll /api/health to confirm the new version is up. Requires the wildcard admin role.",
Tags: []string{"Meta"}, Tags: []string{"Meta"},
Metadata: map[string]any{"module": "meta", "permission": "root"}, Metadata: map[string]any{"module": "meta", "permission": "root"},
Errors: []int{401, 403, 500}, Errors: []int{400, 401, 403, 500},
DefaultStatus: 202, DefaultStatus: 202,
}, func(ctx context.Context, _ *struct{}) (*oscmd.StatusOutput, error) { }, func(ctx context.Context, _ *struct{}) (*oscmd.StatusOutput, error) {
if ConfigPath != "" {
cfg, err := config.Load(ConfigPath)
if err != nil {
return nil, huma.Error500InternalServerError("config load failed", err)
}
if cfg.Server.ReleaseRepo == "" {
return nil, huma.Error400BadRequest("server.release_repo not set in " + ConfigPath)
}
}
exe, err := os.Executable() exe, err := os.Executable()
if err != nil { if err != nil {
return nil, huma.Error500InternalServerError("could not resolve own binary path", err) return nil, huma.Error500InternalServerError("could not resolve own binary path", err)
+12 -3
View File
@@ -159,9 +159,18 @@ func cpuInfo() CPUInfo {
c := CPUInfo{Model: cpuModel(string(data)), LogicalCPUs: runtime.NumCPU()} c := CPUInfo{Model: cpuModel(string(data)), LogicalCPUs: runtime.NumCPU()}
c.MinMHz, c.MaxMHz, c.CurrentMHz = cpuFreqMHz("/sys/devices/system/cpu") c.MinMHz, c.MaxMHz, c.CurrentMHz = cpuFreqMHz("/sys/devices/system/cpu")
// ponytail: cpufreq sysfs is absent on many VMs and stock Ubuntu server // ponytail: cpufreq sysfs is absent on many VMs and stock Ubuntu server
// kernels; fall back to /proc/cpuinfo "cpu MHz" so CurrentMHz isn't 0. // kernels; fall back to /proc/cpuinfo "cpu MHz" — VMs have a fixed clock,
if c.CurrentMHz == 0 { // so min == max == cur is the honest answer.
c.CurrentMHz = cpuinfoMaxMHz(string(data)) if mhz := cpuinfoMaxMHz(string(data)); mhz > 0 {
if c.CurrentMHz == 0 {
c.CurrentMHz = mhz
}
if c.MaxMHz == 0 {
c.MaxMHz = mhz
}
if c.MinMHz == 0 {
c.MinMHz = mhz
}
} }
return c return c
} }
BIN
View File
Binary file not shown.