diff --git a/config/v3_4_experimental/types/unit.go b/config/v3_4_experimental/types/unit.go index f0552800d9..8dcd5af496 100644 --- a/config/v3_4_experimental/types/unit.go +++ b/config/v3_4_experimental/types/unit.go @@ -29,6 +29,11 @@ import ( ) func (u Unit) Key() string { +<<<<<<< HEAD +======= + // Change unit Key to differenciate them by concatenating their scope and name + // to handle the case of same named units for differents scope +>>>>>>> 987794fb9832a7e28d5229b82cfd7bd1d6dafed6 if u.Scope != nil { return *u.Scope + "." + u.Name } else { diff --git a/internal/exec/stages/files/units.go b/internal/exec/stages/files/units.go index 1bbafa11b2..f3117b6047 100644 --- a/internal/exec/stages/files/units.go +++ b/internal/exec/stages/files/units.go @@ -91,8 +91,11 @@ func (s *stage) createUnits(config types.Config) error { // relabelpaths := []string{} if err := s.Logger.LogOp( func() error { +<<<<<<< HEAD // var err error // relabelpaths, err = s.MaskUnit(unit) +======= +>>>>>>> 987794fb9832a7e28d5229b82cfd7bd1d6dafed6 var err error = s.MaskUnit(unit) return err }, @@ -101,10 +104,13 @@ func (s *stage) createUnits(config types.Config) error { return err } +<<<<<<< HEAD // for _, path := range relabelpaths { // s.relabel(path[len(s.DestDir):]) // } +======= +>>>>>>> 987794fb9832a7e28d5229b82cfd7bd1d6dafed6 } else { // mask: false masked, err := s.IsUnitMasked(unit) if err != nil { @@ -125,10 +131,13 @@ func (s *stage) createUnits(config types.Config) error { } // if we have presets then create the systemd preset file. if len(presets) != 0 { +<<<<<<< HEAD // useless as it will be done later in createSystemdPresetFiles // if err := s.relabelPath(filepath.Join(s.DestDir, util.PresetPath)); err != nil { // return err // } +======= +>>>>>>> 987794fb9832a7e28d5229b82cfd7bd1d6dafed6 if err := s.createSystemdPresetFiles(presets); err != nil { return err } @@ -170,7 +179,10 @@ func (s *stage) createSystemdPresetFiles(presets map[string]*Preset) error { paths[path] = true } } +<<<<<<< HEAD +======= +>>>>>>> 987794fb9832a7e28d5229b82cfd7bd1d6dafed6 hasInstanceUnit := false for _, preset := range presets { unitString := preset.unit @@ -205,7 +217,10 @@ func (s *stage) createSystemdPresetFiles(presets map[string]*Preset) error { return err } } +<<<<<<< HEAD +======= +>>>>>>> 987794fb9832a7e28d5229b82cfd7bd1d6dafed6 return nil } diff --git a/internal/exec/stages/files/units_test.go b/internal/exec/stages/files/units_test.go index be5b70356c..cf47acabff 100644 --- a/internal/exec/stages/files/units_test.go +++ b/internal/exec/stages/files/units_test.go @@ -174,11 +174,19 @@ func TestSystemdPresetPath(t *testing.T) { }, { types.Unit{Name: "test.service", Scope: cfgutil.StrToPtr("user")}, +<<<<<<< HEAD "etc/systemd/user-preset/21-ignition-user.preset", }, { types.Unit{Name: "test.service", Scope: cfgutil.StrToPtr("global")}, "etc/systemd/user-preset/20-ignition-global.preset", +======= + "etc/systemd/user-preset/21-ignition.preset", + }, + { + types.Unit{Name: "test.service", Scope: cfgutil.StrToPtr("global")}, + "etc/systemd/user-preset/20-ignition.preset", +>>>>>>> 987794fb9832a7e28d5229b82cfd7bd1d6dafed6 }, } diff --git a/internal/exec/util/path.go b/internal/exec/util/path.go index 770d9836ab..a6a3b12cfd 100755 --- a/internal/exec/util/path.go +++ b/internal/exec/util/path.go @@ -44,11 +44,19 @@ func (u Util) SystemdUnitPaths(unit types.Unit) []string { func (u Util) SystemdPresetPath(scope UnitScope) string { switch scope { case UserUnit: +<<<<<<< HEAD return filepath.Join("etc", "systemd", "user-preset", "21-ignition-user.preset") case SystemUnit: return filepath.Join("etc", "systemd", "system-preset", "20-ignition.preset") case GlobalUnit: return filepath.Join("etc", "systemd", "user-preset", "20-ignition-global.preset") +======= + return filepath.Join("etc", "systemd", "user-preset", "21-ignition.preset") + case SystemUnit: + return filepath.Join("etc", "systemd", "system-preset", "20-ignition.preset") + case GlobalUnit: + return filepath.Join("etc", "systemd", "user-preset", "20-ignition.preset") +>>>>>>> 987794fb9832a7e28d5229b82cfd7bd1d6dafed6 default: return filepath.Join("etc", "systemd", "system-preset", "20-ignition.preset") } diff --git a/internal/exec/util/unit.go b/internal/exec/util/unit.go index f1841a362d..7d2a303d11 100755 --- a/internal/exec/util/unit.go +++ b/internal/exec/util/unit.go @@ -26,7 +26,10 @@ import ( ) const ( +<<<<<<< HEAD // PresetPath string = "/etc/systemd/system-preset/20-ignition.preset" +======= +>>>>>>> 987794fb9832a7e28d5229b82cfd7bd1d6dafed6 DefaultPresetPermissions os.FileMode = 0644 ) @@ -97,6 +100,7 @@ func (ut Util) FilesFromSystemdUnitDropin(unit types.Unit, dropin types.Dropin) return fetchops, nil } +<<<<<<< HEAD // MaskUnit writes a symlink to /dev/null to mask the specified unit and returns the path of that unit // without the sysroot prefix // func (ut Util) MaskUnit(unit types.Unit) ([]string, error) { @@ -123,6 +127,9 @@ func (ut Util) FilesFromSystemdUnitDropin(unit types.Unit, dropin types.Dropin) // return paths, nil // } +======= +// MaskUnit writes a symlink to /dev/null to mask the specified unit +>>>>>>> 987794fb9832a7e28d5229b82cfd7bd1d6dafed6 func (ut Util) MaskUnit(unit types.Unit) error { for _, path := range ut.SystemdUnitPaths(unit) { unitpath, err := ut.JoinPath(path, unit.Name) diff --git a/tests/positive/systemd/create_unit.go b/tests/positive/systemd/create_unit.go index 1964a60278..2be8c56203 100644 --- a/tests/positive/systemd/create_unit.go +++ b/tests/positive/systemd/create_unit.go @@ -21,6 +21,7 @@ import ( func init() { register.Register(register.PositiveTest, CreateSystemdService()) + register.Register(register.PositiveTest, CreateSystemdUserService()) } func CreateSystemdService() types.Test { @@ -63,3 +64,92 @@ func CreateSystemdService() types.Test { ConfigMinVersion: configMinVersion, } } + +func CreateSystemdUserService() types.Test { + name := "systemd.unit.userunit.create" + in := types.GetBaseDisk() + out := types.GetBaseDisk() + config := `{ + "ignition": { "version": "$version" }, + "systemd": { + "units": [{ + "name": "example.service", + "enabled": true, + "scope": "user", + "users": ["tester1", "tester2"], + "contents": "[Service]\nType=oneshot\nExecStart=/usr/bin/echo Hello World\n\n[Install]\nWantedBy=multi-user.target" + }, + { + "contents": "[Service]\nType=oneshot\nExecStart=/usr/bin/echo Hello World\n\n[Install]\nWantedBy=multi-user.target", + "enabled": true, + "name": "example.service", + "scope": "global" + }] + } + }` + configMinVersion := "3.4.0-experimental" + + in[0].Partitions.AddFiles("ROOT", []types.File{ + { + Node: types.Node{ + Name: "passwd", + Directory: "etc", + }, + Contents: "tester1:x:44:4242::/home/tester1:/bin/false\ntester2:x:45:4242::/home/tester2:/bin/false", + }, + { + Node: types.Node{ + Name: "nsswitch.conf", + Directory: "etc", + }, + Contents: "passwd: files\ngroup: files\nshadow: files\ngshadow: files\n", + }, + }) + + out[0].Partitions.AddFiles("ROOT", []types.File{ + { + Node: types.Node{ + Name: "example.service", + Directory: "home/tester1/.config/systemd/user", + }, + Contents: "[Service]\nType=oneshot\nExecStart=/usr/bin/echo Hello World\n\n[Install]\nWantedBy=multi-user.target", + }, + { + Node: types.Node{ + Name: "example.service", + Directory: "home/tester2/.config/systemd/user", + }, + Contents: "[Service]\nType=oneshot\nExecStart=/usr/bin/echo Hello World\n\n[Install]\nWantedBy=multi-user.target", + }, + { + Node: types.Node{ + Name: "21-ignition.preset", + Directory: "etc/systemd/user-preset", + }, + Contents: "enable example.service\n", + }, + + { + Node: types.Node{ + Name: "example.service", + Directory: "etc/systemd/user", + }, + Contents: "[Service]\nType=oneshot\nExecStart=/usr/bin/echo Hello World\n\n[Install]\nWantedBy=multi-user.target", + }, + { + Node: types.Node{ + Name: "20-ignition.preset", + Directory: "etc/systemd/user-preset", + }, + Contents: "enable example.service\n", + }, + }) + + return types.Test{ + Name: name, + In: in, + Out: out, + Config: config, + ConfigMinVersion: configMinVersion, + } +}