Skip to content

fix(schedule): fall back when systemctl list-units ignores JSON - #679

Open
MrBeldum wants to merge 1 commit into
creativeprojects:masterfrom
MrBeldum:fix/516-systemd-list-units-plain-fallback
Open

MrBeldum wants to merge 1 commit into
creativeprojects:masterfrom
MrBeldum:fix/516-systemd-list-units-plain-fallback

Conversation

@MrBeldum

Copy link
Copy Markdown

Summary

On older systemd (AlmaLinux 8 / Amazon Linux 2), systemctl list-units --output=json is ignored and the classic table is printed instead. unschedule / Scheduled() then failed with:

  • error decoding JSON: invalid character 'U'... (UNIT header)
  • json: cannot unmarshal number into Go value of type []schedule.SystemdUnit (footer like 2 loaded units listed)

This change:

  • Still prefers JSON when systemd supports it
  • Falls back to parsing the classic table from the same output
  • If needed, re-runs with --plain --no-legend for a cleaner whitespace-separated format
  • Adds unit tests covering AlmaLinux-style tables, numeric footers, JSON success, and broken JSON

Fixes #516

Test plan

  • go test ./schedule/ -count=1 -run 'SystemctlUnits|ParseSystemctl|DecodeSystemctl|DetectPermissionSystemd|HandlerSystemd$'
  • On AlmaLinux 8 / Amazon Linux 2: resticprofile unschedule no longer logs JSON decode errors
  • On modern systemd: JSON path still used; schedule/unschedule unchanged

Older systemd (AlmaLinux 8, Amazon Linux 2) ignores --output=json for
list-units and prints the classic table, which made unschedule fail with
"error decoding JSON". Prefer JSON when available, otherwise parse the
plain table (and re-run with --plain --no-legend if needed).

Fixes creativeprojects#516
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"cannot list system units: error decoding JSON" during unschedule

1 participant