docker.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package docker
  2. import (
  3. "syscall"
  4. "github.com/rancher/os/config"
  5. "github.com/rancher/os/pkg/dfs"
  6. )
  7. func Start(cfg *config.CloudConfig) (chan interface{}, error) {
  8. launchConfig, args := GetLaunchConfig(cfg, &cfg.Rancher.BootstrapDocker)
  9. launchConfig.Fork = true
  10. launchConfig.LogFile = ""
  11. launchConfig.NoLog = true
  12. cmd, err := dfs.LaunchDocker(launchConfig, config.SystemDockerBin, args...)
  13. if err != nil {
  14. return nil, err
  15. }
  16. c := make(chan interface{})
  17. go func() {
  18. <-c
  19. cmd.Process.Signal(syscall.SIGTERM)
  20. cmd.Wait()
  21. c <- struct{}{}
  22. }()
  23. return c, nil
  24. }
  25. func Stop(c chan interface{}) error {
  26. c <- struct{}{}
  27. <-c
  28. return nil
  29. }
  30. func GetLaunchConfig(cfg *config.CloudConfig, dockerCfg *config.DockerConfig) (*dfs.Config, []string) {
  31. var launchConfig dfs.Config
  32. args := dfs.ParseConfig(&launchConfig, dockerCfg.FullArgs()...)
  33. launchConfig.DNSConfig.Nameservers = cfg.Rancher.Defaults.Network.DNS.Nameservers
  34. launchConfig.DNSConfig.Search = cfg.Rancher.Defaults.Network.DNS.Search
  35. launchConfig.Environment = dockerCfg.Environment
  36. if !cfg.Rancher.Debug {
  37. launchConfig.LogFile = cfg.Rancher.Defaults.SystemDockerLogs
  38. }
  39. return &launchConfig, args
  40. }