kubernetes/kops · warning
error listing systemd units: %v
Error message
error listing systemd units: %v
What it means
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.
Source
Thrown at pkg/dump/dumper.go:550
paths := []string{}
for _, b := range bytes.Split(stdout.Bytes(), []byte{0}) {
if len(b) == 0 {
// Likely the last value
continue
}
paths = append(paths, string(b))
}
return paths, nil
}
// listSystemdUnits returns the list of systemd units on the node
func (n *logDumperNode) listSystemdUnits(ctx context.Context) ([]string, error) {
var stdout bytes.Buffer
var stderr bytes.Buffer
err := n.client.ExecPiped(ctx, "sudo systemctl list-units -t service --no-pager --no-legend --all", &stdout, &stderr)
if err != nil {
return nil, fmt.Errorf("error listing systemd units: %v", err)
}
var services []string
for _, line := range strings.Split(stdout.String(), "\n") {
tokens := strings.Fields(line)
if len(tokens) == 0 || tokens[0] == "" {
continue
}
services = append(services, tokens[0])
}
return services, nil
}
// shellToFile executes a command and copies the output to a file
func (n *logDumperNode) shellToFile(ctx context.Context, command string, destPath string) error {
if err := os.MkdirAll(filepath.Dir(destPath), 0o755); err != nil {
klog.Warningf("unable to mkdir on %q: %v", filepath.Dir(destPath), err)
}View on GitHub (pinned to 4c8573c808)
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.
Defensive patterns
Strategy: validation
Validate before calling
// verify systemctl presence and sudo access before listing units
err := n.client.ExecPiped(ctx, "command -v systemctl && sudo -n true", io.Discard, io.Discard)
if err != nil {
return nil, fmt.Errorf("node not systemd/sudo ready: %w", err)
} Try / catch
services, err := n.listSystemdUnits(ctx)
if err != nil {
if errors.Is(err, context.DeadlineExceeded) {
klog.Warningf("systemctl listing timed out; raise --node-dump-timeout")
}
return nil, fmt.Errorf("error listing systemd units: %w", err)
} Prevention
- Use systemd-based node images.
- Configure NOPASSWD sudo for the dump user.
- SSH in manually and run the systemctl command to baseline remote health.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- error listing systemd services: %v
- error reading /var/log: %v
- error listing /etc/containerd: %v
- error listing %q: %v
- connecting: %w
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/c36e6ff5cf3ac5af.
Report an issue: GitHub.