feat(unit.command): Add command field to units

This commit is contained in:
Brian Waldon
2014-03-19 15:52:24 -07:00
parent 09c473a6cb
commit 88a6e77449
3 changed files with 85 additions and 55 deletions

View File

@@ -114,26 +114,49 @@ func Apply(cfg CloudConfig, env *Environment) error {
}
if len(cfg.Coreos.Units) > 0 {
commands := make(map[string]string, 0)
for _, unit := range cfg.Coreos.Units {
log.Printf("Placing unit %s on filesystem", unit.Name)
dst, err := system.PlaceUnit(&unit, env.Root())
if unit.Content != "" {
log.Printf("Writing unit %s to filesystem", unit.Name)
dst, err := system.PlaceUnit(&unit, env.Root())
if err != nil {
return err
}
log.Printf("Placed unit %s at %s", unit.Name, dst)
if unit.Group() != "network" {
log.Printf("Enabling unit file %s", dst)
if err := system.EnableUnitFile(dst, unit.Runtime); err != nil {
return err
}
log.Printf("Enabled unit %s", unit.Name)
} else {
log.Printf("Skipping enable for network-like unit %s", unit.Name)
}
}
if unit.Group() != "network" {
command := unit.Command
if command == "" {
command = "restart"
}
commands[unit.Name] = command
} else {
commands["systemd-networkd.service"] = "restart"
}
}
system.DaemonReload()
for unit, command := range commands {
log.Printf("Calling unit command '%s %s'", command, unit)
res, err := system.RunUnitCommand(command, unit)
if err != nil {
return err
}
log.Printf("Placed unit %s at %s", unit.Name, dst)
if unit.Group() != "network" {
log.Printf("Enabling unit file %s", dst)
if err := system.EnableUnitFile(dst, unit.Runtime); err != nil {
return err
}
log.Printf("Enabled unit %s", unit.Name)
} else {
log.Printf("Skipping enable for network-like unit %s", unit.Name)
}
log.Printf("Result of '%s %s': %s", command, unit, res)
}
system.DaemonReload()
system.StartUnits(cfg.Coreos.Units)
}
return nil