From b430a5a20e31b59da8cf839ecfdd3c9f5223550c Mon Sep 17 00:00:00 2001 From: Benjamin Gilbert Date: Wed, 12 Jan 2022 11:43:54 -0500 Subject: [PATCH] stages/files: drop support for runtime systemd units It's been unused since 80ca4b2f8340. This effectively reverts af98f37ffdeb. --- internal/exec/stages/files/units.go | 42 ++++++++---------------- internal/exec/util/path.go | 14 -------- internal/exec/util/unit.go | 51 +++-------------------------- 3 files changed, 18 insertions(+), 89 deletions(-) diff --git a/internal/exec/stages/files/units.go b/internal/exec/stages/files/units.go index 88d9f9bf32..3922d65827 100644 --- a/internal/exec/stages/files/units.go +++ b/internal/exec/stages/files/units.go @@ -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" ) @@ -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 { @@ -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 @@ -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 diff --git a/internal/exec/util/path.go b/internal/exec/util/path.go index 44092fa9a8..91ace6741b 100755 --- a/internal/exec/util/path.go +++ b/internal/exec/util/path.go @@ -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") -} diff --git a/internal/exec/util/unit.go b/internal/exec/util/unit.go index 4151423d98..76752aba35 100755 --- a/internal/exec/util/unit.go +++ b/internal/exec/util/unit.go @@ -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" ) @@ -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 @@ -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 @@ -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 @@ -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 @@ -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) }