diff --git a/docs/release-notes.md b/docs/release-notes.md index 0a54977b86..501cda2430 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -25,6 +25,7 @@ Starting with this release, ignition-validate binaries are signed with the - Document that `hash` fields describe decompressed data - Clarify documentation of `passwordHash` fields - Correctly document Tang `advertisement` field as optional +- Fix failure disabling nonexistent unit with systemd ≥ 252 ### Test changes diff --git a/internal/exec/util/unit.go b/internal/exec/util/unit.go index 8e653de070..809507b751 100644 --- a/internal/exec/util/unit.go +++ b/internal/exec/util/unit.go @@ -153,6 +153,12 @@ func (ut Util) EnableUnit(enabledUnit string) error { } func (ut Util) DisableUnit(disabledUnit string) error { + // check if the unit is currently enabled to see if we need to disable it + // if it's not enabled or does not exist, we don't need to do anything + args := []string{"--root", ut.DestDir, "is-enabled", disabledUnit} + if err := exec.Command(distro.SystemctlCmd(), args...).Run(); err != nil { + return nil + } // We need to delete any enablement symlinks for a unit before sending it to a // preset directive. This will help to disable that unit completely. // For more information: https://github.com/coreos/fedora-coreos-tracker/issues/392