diff --git a/initialize/config.go b/initialize/config.go index 660f00b..d4c845c 100644 --- a/initialize/config.go +++ b/initialize/config.go @@ -200,6 +200,7 @@ func processUnits(units []system.Unit, root string, um system.UnitManager) error } actions := make([]action, 0, len(units)) reload := false + restartNetworkd := false for _, unit := range units { if unit.Name == "" { log.Printf("Skipping unit without name") @@ -251,8 +252,7 @@ func processUnits(units []system.Unit, root string, um system.UnitManager) error } if unit.Group() == "network" { - networkd := system.Unit{Unit: config.Unit{Name: "systemd-networkd.service"}} - actions = append(actions, action{networkd, "restart"}) + restartNetworkd = true } else if unit.Command != "" { actions = append(actions, action{unit, unit.Command}) } @@ -264,6 +264,11 @@ func processUnits(units []system.Unit, root string, um system.UnitManager) error } } + if restartNetworkd { + networkd := system.Unit{Unit: config.Unit{Name: "systemd-networkd.service"}} + actions = append(actions, action{networkd, "restart"}) + } + for _, action := range actions { log.Printf("Calling unit command %q on %q'", action.command, action.unit.Name) res, err := um.RunUnitCommand(action.unit, action.command) diff --git a/initialize/config_test.go b/initialize/config_test.go index ed95d58..d3cc3ba 100644 --- a/initialize/config_test.go +++ b/initialize/config_test.go @@ -29,10 +29,15 @@ type TestUnitManager struct { enabled []string masked []string unmasked []string - commands map[string]string + commands []UnitAction reload bool } +type UnitAction struct { + unit string + command string +} + func (tum *TestUnitManager) PlaceUnit(u system.Unit) error { tum.placed = append(tum.placed, u.Name) return nil @@ -46,8 +51,7 @@ func (tum *TestUnitManager) EnableUnitFile(u system.Unit) error { return nil } func (tum *TestUnitManager) RunUnitCommand(u system.Unit, c string) (string, error) { - tum.commands = make(map[string]string) - tum.commands[u.Name] = c + tum.commands = append(tum.commands, UnitAction{u.Name, c}) return "", nil } func (tum *TestUnitManager) DaemonReload() error { @@ -82,13 +86,16 @@ func TestProcessUnits(t *testing.T) { }, { units: []system.Unit{ + system.Unit{Unit: config.Unit{ + Name: "foo.network", + }}, system.Unit{Unit: config.Unit{ Name: "bar.network", }}, }, result: TestUnitManager{ - commands: map[string]string{ - "systemd-networkd.service": "restart", + commands: []UnitAction{ + UnitAction{"systemd-networkd.service", "restart"}, }, }, },