Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b430a5a

Browse files
bgilbertNemric
authored andcommittedJan 12, 2022
stages/files: drop support for runtime systemd units
It's been unused since 80ca4b2. This effectively reverts af98f37.
1 parent 89f4590 commit b430a5a

File tree

3 files changed

+18
-89
lines changed

3 files changed

+18
-89
lines changed
 

‎internal/exec/stages/files/units.go

+14-28
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"github.com/coreos/ignition/v2/config/shared/errors"
2424
cutil "github.com/coreos/ignition/v2/config/util"
2525
"github.com/coreos/ignition/v2/config/v3_4_experimental/types"
26-
"github.com/coreos/ignition/v2/internal/distro"
2726
"github.com/coreos/ignition/v2/internal/exec/util"
2827
"github.com/coreos/ignition/v2/internal/systemd"
2928
)
@@ -55,7 +54,7 @@ func (s *stage) warnOnOldSystemdVersion() error {
5554
func (s *stage) createUnits(config types.Config) error {
5655
presets := make(map[string]*Preset)
5756
for _, unit := range config.Systemd.Units {
58-
if err := s.writeSystemdUnit(unit, false); err != nil {
57+
if err := s.writeSystemdUnit(unit); err != nil {
5958
return err
6059
}
6160
if unit.Enabled != nil {
@@ -213,35 +212,25 @@ func (s *stage) createSystemdPresetFiles(presets map[string]*Preset) error {
213212
// writeSystemdUnit creates the specified unit and any dropins for that unit.
214213
// If the contents of the unit or are empty, the unit is not created. The same
215214
// applies to the unit's dropins.
216-
func (s *stage) writeSystemdUnit(unit types.Unit, runtime bool) error {
217-
// use a different DestDir if it's runtime so it affects our /run (but not
218-
// if we're running locally through blackbox tests)
219-
u := s.Util
220-
if runtime && !distro.BlackboxTesting() {
221-
u.DestDir = "/"
222-
}
223-
215+
func (s *stage) writeSystemdUnit(unit types.Unit) error {
224216
return s.Logger.LogOp(func() error {
225217
relabeledDropinDir := false
226218
for _, dropin := range unit.Dropins {
227219
if dropin.Contents == nil {
228220
continue
229221
}
230-
f, err := u.FileFromSystemdUnitDropin(unit, dropin, runtime)
222+
f, err := s.FileFromSystemdUnitDropin(unit, dropin)
231223
if err != nil {
232224
s.Logger.Crit("error converting systemd dropin: %v", err)
233225
return err
234226
}
235-
relabelPath := f.Node.Path
236-
if !runtime {
237-
// trim off prefix since this needs to be relative to the sysroot
238-
if !strings.HasPrefix(f.Node.Path, s.DestDir) {
239-
panic(fmt.Sprintf("Dropin path %s isn't under prefix %s", f.Node.Path, s.DestDir))
240-
}
241-
relabelPath = f.Node.Path[len(s.DestDir):]
227+
// trim off prefix since this needs to be relative to the sysroot
228+
if !strings.HasPrefix(f.Node.Path, s.DestDir) {
229+
panic(fmt.Sprintf("Dropin path %s isn't under prefix %s", f.Node.Path, s.DestDir))
242230
}
231+
relabelPath := f.Node.Path[len(s.DestDir):]
243232
if err := s.Logger.LogOp(
244-
func() error { return u.PerformFetch(f) },
233+
func() error { return s.PerformFetch(f) },
245234
"writing systemd drop-in %q at %q", dropin.Name, f.Node.Path,
246235
); err != nil {
247236
return err
@@ -256,21 +245,18 @@ func (s *stage) writeSystemdUnit(unit types.Unit, runtime bool) error {
256245
return nil
257246
}
258247

259-
f, err := u.FileFromSystemdUnit(unit, runtime)
248+
f, err := s.FileFromSystemdUnit(unit)
260249
if err != nil {
261250
s.Logger.Crit("error converting unit: %v", err)
262251
return err
263252
}
264-
relabelPath := f.Node.Path
265-
if !runtime {
266-
// trim off prefix since this needs to be relative to the sysroot
267-
if !strings.HasPrefix(f.Node.Path, s.DestDir) {
268-
panic(fmt.Sprintf("Unit path %s isn't under prefix %s", f.Node.Path, s.DestDir))
269-
}
270-
relabelPath = f.Node.Path[len(s.DestDir):]
253+
// trim off prefix since this needs to be relative to the sysroot
254+
if !strings.HasPrefix(f.Node.Path, s.DestDir) {
255+
panic(fmt.Sprintf("Unit path %s isn't under prefix %s", f.Node.Path, s.DestDir))
271256
}
257+
relabelPath := f.Node.Path[len(s.DestDir):]
272258
if err := s.Logger.LogOp(
273-
func() error { return u.PerformFetch(f) },
259+
func() error { return s.PerformFetch(f) },
274260
"writing unit %q at %q", unit.Name, f.Node.Path,
275261
); err != nil {
276262
return err

‎internal/exec/util/path.go

-14
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,3 @@ func SystemdWantsPath(unit types.Unit) string {
4242
func SystemdDropinsPath(unit types.Unit) string {
4343
return filepath.Join(SystemdUnitsPath(unit), unit.Name+".d")
4444
}
45-
46-
//Below specific paths leaved as is
47-
48-
func SystemdRuntimeUnitsPath() string {
49-
return filepath.Join("run", "systemd", "system")
50-
}
51-
52-
func SystemdRuntimeDropinsPath(unitName string) string {
53-
return filepath.Join("run", "systemd", "system", unitName+".d")
54-
}
55-
56-
func SystemdRuntimeUnitWantsPath(unitName string) string {
57-
return filepath.Join("run", "systemd", "system", unitName+".wants")
58-
}

‎internal/exec/util/unit.go

+4-47
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ import (
2121
"path/filepath"
2222
"syscall"
2323

24-
cutil "github.com/coreos/ignition/v2/config/util"
2524
"github.com/coreos/ignition/v2/config/v3_4_experimental/types"
26-
"github.com/coreos/ignition/v2/internal/distro"
2725

2826
"github.com/vincent-petithory/dataurl"
2927
)
@@ -33,7 +31,7 @@ const (
3331
DefaultPresetPermissions os.FileMode = 0644
3432
)
3533

36-
func (ut Util) FileFromSystemdUnit(unit types.Unit, runtime bool) (FetchOp, error) {
34+
func (ut Util) FileFromSystemdUnit(unit types.Unit) (FetchOp, error) {
3735
if unit.Contents == nil {
3836
empty := ""
3937
unit.Contents = &empty
@@ -43,12 +41,7 @@ func (ut Util) FileFromSystemdUnit(unit types.Unit, runtime bool) (FetchOp, erro
4341
return FetchOp{}, err
4442
}
4543

46-
var path string
47-
if runtime {
48-
path = SystemdRuntimeUnitsPath()
49-
} else {
50-
path = SystemdUnitsPath(unit)
51-
}
44+
var path string = SystemdUnitsPath(unit)
5245

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

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

75-
var path string
76-
if runtime {
77-
path = SystemdRuntimeDropinsPath(string(unit.Name))
78-
} else {
79-
path = SystemdDropinsPath(unit)
80-
}
68+
var path string = SystemdDropinsPath(unit)
8169

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

163-
// presets link in /etc, which doesn't make sense for runtime units
164-
// Related: https://github.com/coreos/ignition/v2/issues/588
165-
func (ut Util) EnableRuntimeUnit(unit types.Unit, target string) error {
166-
// unless we're running tests locally, we want to affect /run, which will
167-
// be carried into the pivot, not a directory named /$DestDir/run
168-
if !distro.BlackboxTesting() {
169-
ut.DestDir = "/"
170-
}
171-
172-
nodePath, err := ut.JoinPath(SystemdRuntimeUnitWantsPath(target), unit.Name)
173-
if err != nil {
174-
return err
175-
}
176-
targetPath, err := ut.JoinPath("/", SystemdRuntimeUnitsPath(), unit.Name)
177-
if err != nil {
178-
return err
179-
}
180-
181-
link := types.Link{
182-
Node: types.Node{
183-
// XXX(jl): make Wants/Required a parameter
184-
Path: nodePath,
185-
},
186-
LinkEmbedded1: types.LinkEmbedded1{
187-
Target: cutil.StrToPtr(targetPath),
188-
},
189-
}
190-
191-
return ut.WriteLink(link)
192-
}
193-
194151
func (ut Util) EnableUnit(enabledUnit string, presetpath string) error {
195152
return ut.appendLineToPreset(fmt.Sprintf("enable %s", enabledUnit), presetpath)
196153
}

0 commit comments

Comments
 (0)
Please sign in to comment.