reload.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package control
  2. import (
  3. log "github.com/Sirupsen/logrus"
  4. "github.com/codegangsta/cli"
  5. "github.com/rancherio/os/config"
  6. "github.com/rancherio/os/docker"
  7. )
  8. //func parseContainers(cfg *config.Config) map[string]*docker.Container {
  9. // result := map[string]*docker.Container{}
  10. //
  11. // for _, containerConfig := range cfg.SystemContainers {
  12. // container := docker.NewContainer(config.DOCKER_SYSTEM_HOST, &containerConfig)
  13. // if containerConfig.Id != "" {
  14. // result[containerConfig.Id] = container
  15. // }
  16. // }
  17. //
  18. // return result
  19. //}
  20. func reload(c *cli.Context) {
  21. _, err := config.LoadConfig()
  22. if err != nil {
  23. log.Fatal(err)
  24. }
  25. containers := map[string]*docker.Container{} //parseContainers(cfg)
  26. toStart := make([]*docker.Container, 0, len(c.Args()))
  27. for _, id := range c.Args() {
  28. if container, ok := containers[id]; ok {
  29. toStart = append(toStart, container.Stage())
  30. }
  31. }
  32. var firstErr error
  33. for _, c := range toStart {
  34. err := c.Start().Err
  35. if err != nil {
  36. log.Errorf("Failed to start %s : %v", c.ContainerCfg.Id, err)
  37. if firstErr != nil {
  38. firstErr = err
  39. }
  40. }
  41. }
  42. if firstErr != nil {
  43. log.Fatal(firstErr)
  44. }
  45. }