Skip to content

Commit

Permalink
internal/*: remove enablement symlinks for a unit before disabling
Browse files Browse the repository at this point in the history
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.
This is a short-term solution until the upstream systemd PR (systemd/systemd#15205)
gets accepted.

Fixes coreos/fedora-coreos-tracker#392
  • Loading branch information
sohankunkerkar committed Apr 22, 2022
1 parent 9297e87 commit cf5e0af
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/distro/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var (
userdelCmd = "userdel"
setfilesCmd = "setfiles"
wipefsCmd = "wipefs"
systemctl = "systemctl"

// Filesystem tools
btrfsMkfsCmd = "mkfs.btrfs"
Expand Down Expand Up @@ -96,6 +97,7 @@ func UseraddCmd() string { return useraddCmd }
func UserdelCmd() string { return userdelCmd }
func SetfilesCmd() string { return setfilesCmd }
func WipefsCmd() string { return wipefsCmd }
func SystemCtl() string { return systemctl }

func BtrfsMkfsCmd() string { return btrfsMkfsCmd }
func Ext4MkfsCmd() string { return ext4MkfsCmd }
Expand Down
18 changes: 18 additions & 0 deletions internal/exec/util/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import (
"fmt"
"net/url"
"os"
"os/exec"
"path/filepath"
"syscall"

"github.com/coreos/ignition/v2/config/v3_4_experimental/types"
"github.com/coreos/ignition/v2/internal/distro"

"github.com/vincent-petithory/dataurl"
)
Expand Down Expand Up @@ -151,6 +153,22 @@ func (ut Util) EnableUnit(enabledUnit string) error {
}

func (ut Util) DisableUnit(disabledUnit string) error {
// 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
// This is a short-term solution until the upstream systemd PR
// (https://github.com/systemd/systemd/pull/15205) gets accepted.
if err := ut.Logger.LogOp(
func() error {
if _, err := exec.Command(distro.SystemCtl(), "--root=/sysroot", "disable", disabledUnit).CombinedOutput(); err != nil {
return fmt.Errorf("cannot remove symlink(s) for: %s : %v", disabledUnit, err)
}
return nil
},
"removing enablement symlink(s) for: %q", disabledUnit,
); err != nil {
return err
}
return ut.appendLineToPreset(fmt.Sprintf("disable %s", disabledUnit))
}

Expand Down

0 comments on commit cf5e0af

Please sign in to comment.