reload.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package compose
  2. import (
  3. "fmt"
  4. log "github.com/Sirupsen/logrus"
  5. yaml "github.com/cloudfoundry-incubator/candiedyaml"
  6. "github.com/docker/libcompose/project"
  7. "github.com/rancher/os/config"
  8. "github.com/rancher/os/docker"
  9. "github.com/rancher/os/util/network"
  10. )
  11. func LoadService(p *project.Project, cfg *config.CloudConfig, useNetwork bool, service string) error {
  12. bytes, err := network.LoadServiceResource(service, useNetwork, cfg)
  13. if err != nil {
  14. return err
  15. }
  16. m := map[interface{}]interface{}{}
  17. if err = yaml.Unmarshal(bytes, &m); err != nil {
  18. return fmt.Errorf("Failed to parse YAML configuration for %s: %v", service, err)
  19. }
  20. m = adjustContainerNames(m)
  21. bytes, err = yaml.Marshal(m)
  22. if err != nil {
  23. return fmt.Errorf("Failed to marshal YAML configuration for %s: %v", service, err)
  24. }
  25. if err = p.Load(bytes); err != nil {
  26. return fmt.Errorf("Failed to load %s: %v", service, err)
  27. }
  28. return nil
  29. }
  30. func projectReload(p *project.Project, useNetwork *bool, loadConsole bool, environmentLookup *docker.ConfigEnvironment, authLookup *docker.ConfigAuthLookup) func() error {
  31. enabled := map[interface{}]interface{}{}
  32. return func() error {
  33. cfg := config.LoadConfig()
  34. environmentLookup.SetConfig(cfg)
  35. authLookup.SetConfig(cfg)
  36. enabled = addServices(p, enabled, cfg.Rancher.Services)
  37. for service, serviceEnabled := range cfg.Rancher.ServicesInclude {
  38. if _, ok := enabled[service]; ok || !serviceEnabled {
  39. continue
  40. }
  41. if err := LoadService(p, cfg, *useNetwork, service); err != nil {
  42. if err != network.ErrNoNetwork {
  43. log.Error(err)
  44. }
  45. continue
  46. }
  47. enabled[service] = service
  48. }
  49. if !loadConsole || cfg.Rancher.Console == "" || cfg.Rancher.Console == "default" {
  50. return nil
  51. }
  52. if err := LoadService(p, cfg, *useNetwork, cfg.Rancher.Console); err != nil && err != network.ErrNoNetwork {
  53. log.Error(err)
  54. }
  55. return nil
  56. }
  57. }