Merge pull request #273 from crawford/networkd
initialize: only restart networkd once per config
This commit is contained in:
commit
c628bef666
@ -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)
|
||||
|
@ -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"},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user