Hold a unit an administrator installed whatever its state, and a packaged unit only when the machine uses it (hq ADR 0103)

This commit is contained in:
2026-09-22 19:52:37 +02:00
parent d3f2595968
commit 40e8ea9fda
3 changed files with 103 additions and 5 deletions
+16
View File
@@ -247,6 +247,22 @@ func (arch) AddUserToGroup(ctx context.Context, run Runner, name, group string)
return nil
}
// ServiceUnitFile says where the service manager loads a unit from — systemd's FragmentPath. It
// is how the host tells a unit an administrator installed, under /etc or /run, from one a package
// ships under /usr (novox/hq ADR 0103). Empty, with no error, for a unit that loads from nowhere.
func (arch) ServiceUnitFile(ctx context.Context, run Runner, unit string) (string, error) {
out, err := run(ctx, "systemctl", "show", unit, "--property=FragmentPath")
if err != nil {
return "", fmt.Errorf("the service manager did not say where %s comes from: %w", unit, err)
}
for _, line := range strings.Split(out, "\n") {
if path, ok := strings.CutPrefix(strings.TrimSpace(line), "FragmentPath="); ok {
return strings.TrimSpace(path), nil
}
}
return "", nil
}
// ReloadUnits has systemd read its unit files again. A unit file that changed on disk is otherwise
// ignored: a restart runs the unit systemd already loaded, and the new text only takes effect
// after a reload nobody asked for.