fix parsing systemd
Deploy / deploy (push) Successful in 12s

This commit is contained in:
2026-08-31 16:48:16 +05:00
parent 315ced56bb
commit 8eae79af06
+8 -8
View File
@@ -272,16 +272,16 @@ func (s *server) systemdStatus(ctx context.Context, unit string) *homelabv1.Serv
// show is the machine-readable probe (always exit 0, unlike status). LoadState=not-found means the user // show is the machine-readable probe (always exit 0, unlike status). LoadState=not-found means the user
// disabled the unit on purpose — a state, not an error. // disabled the unit on purpose — a state, not an error.
out, err := exec.CommandContext(ctx, "systemctl", "--user", "show", unit+".service", out, err := exec.CommandContext(ctx, "systemctl", "--user", "show", unit+".service",
"-p", "ActiveState,SubState,LoadState,UnitFileState", "--value").Output() "-p", "ActiveState,SubState,LoadState,UnitFileState").Output()
// one line per property, in the order given to -p // systemctl prints properties in its own fixed table order (not the -p order), so parse by key
v := strings.Split(strings.TrimRight(string(out), "\n"), "\n") props := map[string]string{}
at := func(i int) string { for _, line := range strings.Split(string(out), "\n") {
if i < len(v) { if k, v, ok := strings.Cut(strings.TrimSpace(line), "="); ok {
return strings.TrimSpace(v[i]) props[k] = v
} }
return ""
} }
svc.State, svc.Substate, svc.LoadState, svc.UnitFileState = at(0), at(1), at(2), at(3) svc.State, svc.Substate = props["ActiveState"], props["SubState"]
svc.LoadState, svc.UnitFileState = props["LoadState"], props["UnitFileState"]
if svc.LoadState == "" { if svc.LoadState == "" {
svc.LoadState = "not-found" svc.LoadState = "not-found"
} }