diff --git a/server/main.go b/server/main.go index bdbc56a..7a2c997 100644 --- a/server/main.go +++ b/server/main.go @@ -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 // disabled the unit on purpose — a state, not an error. out, err := exec.CommandContext(ctx, "systemctl", "--user", "show", unit+".service", - "-p", "ActiveState,SubState,LoadState,UnitFileState", "--value").Output() - // one line per property, in the order given to -p - v := strings.Split(strings.TrimRight(string(out), "\n"), "\n") - at := func(i int) string { - if i < len(v) { - return strings.TrimSpace(v[i]) + "-p", "ActiveState,SubState,LoadState,UnitFileState").Output() + // systemctl prints properties in its own fixed table order (not the -p order), so parse by key + props := map[string]string{} + for _, line := range strings.Split(string(out), "\n") { + if k, v, ok := strings.Cut(strings.TrimSpace(line), "="); ok { + 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 == "" { svc.LoadState = "not-found" }