{"record":{"id":"c36e6ff5cf3ac5af","repo":"kubernetes/kops","slug":"error-listing-systemd-units-v","errorCode":null,"errorMessage":"error listing systemd units: %v","messagePattern":"error listing systemd units: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/dump/dumper.go","lineNumber":550,"sourceCode":"\tpaths := []string{}\n\tfor _, b := range bytes.Split(stdout.Bytes(), []byte{0}) {\n\t\tif len(b) == 0 {\n\t\t\t// Likely the last value\n\t\t\tcontinue\n\t\t}\n\t\tpaths = append(paths, string(b))\n\t}\n\treturn paths, nil\n}\n\n// listSystemdUnits returns the list of systemd units on the node\nfunc (n *logDumperNode) listSystemdUnits(ctx context.Context) ([]string, error) {\n\tvar stdout bytes.Buffer\n\tvar stderr bytes.Buffer\n\n\terr := n.client.ExecPiped(ctx, \"sudo systemctl list-units -t service --no-pager --no-legend --all\", &stdout, &stderr)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error listing systemd units: %v\", err)\n\t}\n\n\tvar services []string\n\tfor _, line := range strings.Split(stdout.String(), \"\\n\") {\n\t\ttokens := strings.Fields(line)\n\t\tif len(tokens) == 0 || tokens[0] == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\tservices = append(services, tokens[0])\n\t}\n\treturn services, nil\n}\n\n// shellToFile executes a command and copies the output to a file\nfunc (n *logDumperNode) shellToFile(ctx context.Context, command string, destPath string) error {\n\tif err := os.MkdirAll(filepath.Dir(destPath), 0o755); err != nil {\n\t\tklog.Warningf(\"unable to mkdir on %q: %v\", filepath.Dir(destPath), err)\n\t}","sourceCodeStart":532,"sourceCodeEnd":568,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/dump/dumper.go#L532-L568","documentation":"Returned by logDumperNode.listSystemdUnits (pkg/dump/dumper.go:550) when the SSH ExecPiped of `sudo systemctl list-units -t service --no-pager --no-legend --all` fails. This is the root-cause error surfaced (wrapped) to callers as 'error listing systemd services'; it prevents matching the dumper's configured service list against the node's actual units.","triggerScenarios":"ExecPiped fails because: systemctl is not installed (non-systemd image like Alpine), the remote command exits non-zero (sudo denied), the SSH session is closed/reset, or the dumpNode context (1-minute nodeDumpTimeout) expires before the command finishes.","commonSituations":"Dumping nodes built from non-systemd base images; sudoers requiring a TTY/password; node under heavy load or out of memory so systemctl is slow; SSH session killed by network middleboxes during long dumps.","solutions":["SSH to the node and run the exact systemctl command to see the real exit code/stderr.","If systemctl is absent (non-systemd image), accept the warning or switch to a systemd-based node image.","Ensure passwordless sudo (NOPASSWD) is configured for the dump user.","Raise --node-dump-timeout if the error wraps context.DeadlineExceeded.","Retry the dump; check node health (dmesg, disk, memory) if systemctl hangs or fails intermittently."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// verify systemctl presence and sudo access before listing units\nerr := n.client.ExecPiped(ctx, \"command -v systemctl && sudo -n true\", io.Discard, io.Discard)\nif err != nil {\n    return nil, fmt.Errorf(\"node not systemd/sudo ready: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"services, err := n.listSystemdUnits(ctx)\nif err != nil {\n    if errors.Is(err, context.DeadlineExceeded) {\n        klog.Warningf(\"systemctl listing timed out; raise --node-dump-timeout\")\n    }\n    return nil, fmt.Errorf(\"error listing systemd units: %w\", err)\n}","preventionTips":["Use systemd-based node images.","Configure NOPASSWD sudo for the dump user.","SSH in manually and run the systemctl command to baseline remote health."],"tags":["ssh","systemd","node-dump","go"],"backgroundTag":"remote-command-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}