Skip to content

Commit

Permalink
stages/files: drop support for runtime systemd units
Browse files Browse the repository at this point in the history
It's been unused since 80ca4b2.

This effectively reverts af98f37.
  • Loading branch information
bgilbert authored and Nemric committed Jan 12, 2022
1 parent 89f4590 commit b430a5a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 89 deletions.
42 changes: 14 additions & 28 deletions internal/exec/stages/files/units.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/coreos/ignition/v2/config/shared/errors"
cutil "github.com/coreos/ignition/v2/config/util"
"github.com/coreos/ignition/v2/config/v3_4_experimental/types"
"github.com/coreos/ignition/v2/internal/distro"
"github.com/coreos/ignition/v2/internal/exec/util"
"github.com/coreos/ignition/v2/internal/systemd"
)
Expand Down Expand Up @@ -55,7 +54,7 @@ func (s *stage) warnOnOldSystemdVersion() error {
func (s *stage) createUnits(config types.Config) error {
presets := make(map[string]*Preset)
for _, unit := range config.Systemd.Units {
if err := s.writeSystemdUnit(unit, false); err != nil {
if err := s.writeSystemdUnit(unit); err != nil {
return err
}
if unit.Enabled != nil {
Expand Down Expand Up @@ -213,35 +212,25 @@ func (s *stage) createSystemdPresetFiles(presets map[string]*Preset) error {
// writeSystemdUnit creates the specified unit and any dropins for that unit.
// If the contents of the unit or are empty, the unit is not created. The same
// applies to the unit's dropins.
func (s *stage) writeSystemdUnit(unit types.Unit, runtime bool) error {
// use a different DestDir if it's runtime so it affects our /run (but not
// if we're running locally through blackbox tests)
u := s.Util
if runtime && !distro.BlackboxTesting() {
u.DestDir = "/"
}

func (s *stage) writeSystemdUnit(unit types.Unit) error {
return s.Logger.LogOp(func() error {
relabeledDropinDir := false
for _, dropin := range unit.Dropins {
if dropin.Contents == nil {
continue
}
f, err := u.FileFromSystemdUnitDropin(unit, dropin, runtime)
f, err := s.FileFromSystemdUnitDropin(unit, dropin)
if err != nil {
s.Logger.Crit("error converting systemd dropin: %v", err)
return err
}
relabelPath := f.Node.Path
if !runtime {
// trim off prefix since this needs to be relative to the sysroot
if !strings.HasPrefix(f.Node.Path, s.DestDir) {
panic(fmt.Sprintf("Dropin path %s isn't under prefix %s", f.Node.Path, s.DestDir))
}
relabelPath = f.Node.Path[len(s.DestDir):]
// trim off prefix since this needs to be relative to the sysroot
if !strings.HasPrefix(f.Node.Path, s.DestDir) {
panic(fmt.Sprintf("Dropin path %s isn't under prefix %s", f.Node.Path, s.DestDir))
}
relabelPath := f.Node.Path[len(s.DestDir):]
if err := s.Logger.LogOp(
func() error { return u.PerformFetch(f) },
func() error { return s.PerformFetch(f) },
"writing systemd drop-in %q at %q", dropin.Name, f.Node.Path,
); err != nil {
return err
Expand All @@ -256,21 +245,18 @@ func (s *stage) writeSystemdUnit(unit types.Unit, runtime bool) error {
return nil
}

f, err := u.FileFromSystemdUnit(unit, runtime)
f, err := s.FileFromSystemdUnit(unit)
if err != nil {
s.Logger.Crit("error converting unit: %v", err)
return err
}
relabelPath := f.Node.Path
if !runtime {
// trim off prefix since this needs to be relative to the sysroot
if !strings.HasPrefix(f.Node.Path, s.DestDir) {
panic(fmt.Sprintf("Unit path %s isn't under prefix %s", f.Node.Path, s.DestDir))
}
relabelPath = f.Node.Path[len(s.DestDir):]
// trim off prefix since this needs to be relative to the sysroot
if !strings.HasPrefix(f.Node.Path, s.DestDir) {
panic(fmt.Sprintf("Unit path %s isn't under prefix %s", f.Node.Path, s.DestDir))
}
relabelPath := f.Node.Path[len(s.DestDir):]
if err := s.Logger.LogOp(
func() error { return u.PerformFetch(f) },
func() error { return s.PerformFetch(f) },
"writing unit %q at %q", unit.Name, f.Node.Path,
); err != nil {
return err
Expand Down
14 changes: 0 additions & 14 deletions internal/exec/util/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,3 @@ func SystemdWantsPath(unit types.Unit) string {
func SystemdDropinsPath(unit types.Unit) string {
return filepath.Join(SystemdUnitsPath(unit), unit.Name+".d")
}

//Below specific paths leaved as is

func SystemdRuntimeUnitsPath() string {
return filepath.Join("run", "systemd", "system")
}

func SystemdRuntimeDropinsPath(unitName string) string {
return filepath.Join("run", "systemd", "system", unitName+".d")
}

func SystemdRuntimeUnitWantsPath(unitName string) string {
return filepath.Join("run", "systemd", "system", unitName+".wants")
}
51 changes: 4 additions & 47 deletions internal/exec/util/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import (
"path/filepath"
"syscall"

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

"github.com/vincent-petithory/dataurl"
)
Expand All @@ -33,7 +31,7 @@ const (
DefaultPresetPermissions os.FileMode = 0644
)

func (ut Util) FileFromSystemdUnit(unit types.Unit, runtime bool) (FetchOp, error) {
func (ut Util) FileFromSystemdUnit(unit types.Unit) (FetchOp, error) {
if unit.Contents == nil {
empty := ""
unit.Contents = &empty
Expand All @@ -43,12 +41,7 @@ func (ut Util) FileFromSystemdUnit(unit types.Unit, runtime bool) (FetchOp, erro
return FetchOp{}, err
}

var path string
if runtime {
path = SystemdRuntimeUnitsPath()
} else {
path = SystemdUnitsPath(unit)
}
var path string = SystemdUnitsPath(unit)

if path, err = ut.JoinPath(path, unit.Name); err != nil {
return FetchOp{}, err
Expand All @@ -62,7 +55,7 @@ func (ut Util) FileFromSystemdUnit(unit types.Unit, runtime bool) (FetchOp, erro
}, nil
}

func (ut Util) FileFromSystemdUnitDropin(unit types.Unit, dropin types.Dropin, runtime bool) (FetchOp, error) {
func (ut Util) FileFromSystemdUnitDropin(unit types.Unit, dropin types.Dropin) (FetchOp, error) {
if dropin.Contents == nil {
empty := ""
dropin.Contents = &empty
Expand All @@ -72,12 +65,7 @@ func (ut Util) FileFromSystemdUnitDropin(unit types.Unit, dropin types.Dropin, r
return FetchOp{}, err
}

var path string
if runtime {
path = SystemdRuntimeDropinsPath(string(unit.Name))
} else {
path = SystemdDropinsPath(unit)
}
var path string = SystemdDropinsPath(unit)

if path, err = ut.JoinPath(path, dropin.Name); err != nil {
return FetchOp{}, err
Expand Down Expand Up @@ -160,37 +148,6 @@ func (ut Util) IsUnitMasked(unit types.Unit) (bool, error) {
return true, nil
}

// presets link in /etc, which doesn't make sense for runtime units
// Related: https://github.com/coreos/ignition/v2/issues/588
func (ut Util) EnableRuntimeUnit(unit types.Unit, target string) error {
// unless we're running tests locally, we want to affect /run, which will
// be carried into the pivot, not a directory named /$DestDir/run
if !distro.BlackboxTesting() {
ut.DestDir = "/"
}

nodePath, err := ut.JoinPath(SystemdRuntimeUnitWantsPath(target), unit.Name)
if err != nil {
return err
}
targetPath, err := ut.JoinPath("/", SystemdRuntimeUnitsPath(), unit.Name)
if err != nil {
return err
}

link := types.Link{
Node: types.Node{
// XXX(jl): make Wants/Required a parameter
Path: nodePath,
},
LinkEmbedded1: types.LinkEmbedded1{
Target: cutil.StrToPtr(targetPath),
},
}

return ut.WriteLink(link)
}

func (ut Util) EnableUnit(enabledUnit string, presetpath string) error {
return ut.appendLineToPreset(fmt.Sprintf("enable %s", enabledUnit), presetpath)
}
Expand Down

0 comments on commit b430a5a

Please sign in to comment.