init.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // +build linux
  2. package init
  3. import (
  4. "fmt"
  5. "github.com/rancher/os/config"
  6. "github.com/rancher/os/pkg/dfs"
  7. "github.com/rancher/os/pkg/init/b2d"
  8. "github.com/rancher/os/pkg/init/cloudinit"
  9. "github.com/rancher/os/pkg/init/configfiles"
  10. "github.com/rancher/os/pkg/init/debug"
  11. "github.com/rancher/os/pkg/init/docker"
  12. "github.com/rancher/os/pkg/init/env"
  13. "github.com/rancher/os/pkg/init/fsmount"
  14. "github.com/rancher/os/pkg/init/hypervisor"
  15. "github.com/rancher/os/pkg/init/modules"
  16. "github.com/rancher/os/pkg/init/one"
  17. "github.com/rancher/os/pkg/init/prepare"
  18. "github.com/rancher/os/pkg/init/recovery"
  19. "github.com/rancher/os/pkg/init/selinux"
  20. "github.com/rancher/os/pkg/init/sharedroot"
  21. "github.com/rancher/os/pkg/init/switchroot"
  22. "github.com/rancher/os/pkg/log"
  23. "github.com/rancher/os/pkg/sysinit"
  24. )
  25. func MainInit() {
  26. log.InitLogger()
  27. // TODO: this breaks and does nothing if the cfg is invalid (or is it due to threading?)
  28. defer func() {
  29. if r := recover(); r != nil {
  30. fmt.Printf("Starting Recovery console: %v\n", r)
  31. recovery.Recovery(nil)
  32. }
  33. }()
  34. if err := RunInit(); err != nil {
  35. log.Fatal(err)
  36. }
  37. }
  38. func RunInit() error {
  39. initFuncs := config.CfgFuncs{
  40. {"set env", env.Init},
  41. {"preparefs", prepare.FS},
  42. {"save init cmdline", prepare.SaveCmdline},
  43. {"mount OEM", fsmount.MountOem},
  44. {"debug save cfg", debug.PrintAndLoadConfig},
  45. {"load modules", modules.LoadModules},
  46. {"recovery console", recovery.LoadRecoveryConsole},
  47. {"b2d env", b2d.B2D},
  48. {"mount STATE and bootstrap", fsmount.MountStateAndBootstrap},
  49. {"cloud-init", cloudinit.CloudInit},
  50. {"read cfg and log files", configfiles.ReadConfigFiles},
  51. {"switchroot", switchroot.SwitchRoot},
  52. {"mount OEM2", fsmount.MountOem},
  53. {"mount BOOT", fsmount.MountBoot},
  54. {"write cfg and log files", configfiles.WriteConfigFiles},
  55. {"b2d Env", b2d.Env},
  56. {"hypervisor tools", hypervisor.Tools},
  57. {"preparefs2", prepare.FS},
  58. {"load modules2", modules.LoadModules},
  59. {"set proxy env", env.Proxy},
  60. {"init SELinux", selinux.Initialize},
  61. {"setupSharedRoot", sharedroot.Setup},
  62. {"sysinit", sysinit.RunSysInit},
  63. }
  64. cfg, err := config.ChainCfgFuncs(nil, initFuncs)
  65. if err != nil {
  66. recovery.Recovery(err)
  67. }
  68. launchConfig, args := docker.GetLaunchConfig(cfg, &cfg.Rancher.SystemDocker)
  69. launchConfig.Fork = !cfg.Rancher.SystemDocker.Exec
  70. //launchConfig.NoLog = true
  71. log.Info("Launching System Docker")
  72. _, err = dfs.LaunchDocker(launchConfig, config.SystemDockerBin, args...)
  73. if err != nil {
  74. log.Errorf("Error Launching System Docker: %s", err)
  75. recovery.Recovery(err)
  76. return err
  77. }
  78. // Code never gets here - rancher.system_docker.exec=true
  79. return one.PidOne()
  80. }