recovery.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package init
  2. import (
  3. log "github.com/Sirupsen/logrus"
  4. composeConfig "github.com/docker/libcompose/config"
  5. "github.com/docker/libcompose/yaml"
  6. "github.com/rancher/os/compose"
  7. "github.com/rancher/os/config"
  8. "github.com/rancher/os/netconf"
  9. )
  10. var (
  11. // TODO: move this into the os-config file so it can be customised.
  12. recoveryDockerService = composeConfig.ServiceConfigV1{
  13. Image: config.OsBase,
  14. Command: yaml.Command{
  15. "ros",
  16. "recovery-init",
  17. },
  18. Labels: map[string]string{
  19. config.DetachLabel: "false",
  20. config.ScopeLabel: "system",
  21. },
  22. LogDriver: "json-file",
  23. Net: "host",
  24. Uts: "host",
  25. Pid: "host",
  26. Ipc: "host",
  27. Privileged: true,
  28. Volumes: []string{
  29. "/dev:/host/dev",
  30. "/etc/ssl/certs/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt.rancher",
  31. "/lib/modules:/lib/modules",
  32. "/lib/firmware:/lib/firmware",
  33. "/usr/bin/ros:/usr/bin/ros:ro",
  34. "/usr/bin/ros:/usr/bin/cloud-init-save",
  35. "/usr/bin/ros:/usr/bin/respawn:ro",
  36. "/usr/share/ros:/usr/share/ros:ro",
  37. "/var/lib/rancher:/var/lib/rancher",
  38. "/var/lib/rancher/conf:/var/lib/rancher/conf",
  39. "/var/run:/var/run",
  40. },
  41. }
  42. )
  43. func recoveryServices(cfg *config.CloudConfig) (*config.CloudConfig, error) {
  44. _, err := compose.RunServiceSet("recovery", cfg, map[string]*composeConfig.ServiceConfigV1{
  45. "recovery": &recoveryDockerService,
  46. })
  47. return nil, err
  48. }
  49. func recovery(initFailure error) {
  50. if initFailure != nil {
  51. log.Errorf("RancherOS has failed to boot: %v", initFailure)
  52. }
  53. log.Info("Launching recovery console")
  54. var recoveryConfig config.CloudConfig
  55. recoveryConfig.Rancher.Defaults = config.Defaults{
  56. Network: netconf.NetworkConfig{
  57. DNS: netconf.DNSConfig{
  58. Nameservers: []string{
  59. "8.8.8.8",
  60. "8.8.4.4",
  61. },
  62. },
  63. },
  64. }
  65. recoveryConfig.Rancher.BootstrapDocker = config.DockerConfig{
  66. EngineOpts: config.EngineOpts{
  67. Bridge: "none",
  68. StorageDriver: "overlay",
  69. Restart: &[]bool{false}[0],
  70. Graph: "/var/lib/recovery-docker",
  71. Group: "root",
  72. Host: []string{"unix:///var/run/system-docker.sock"},
  73. UserlandProxy: &[]bool{false}[0],
  74. },
  75. }
  76. _, err := startDocker(&recoveryConfig)
  77. if err != nil {
  78. log.Fatal(err)
  79. }
  80. _, err = config.ChainCfgFuncs(&recoveryConfig,
  81. []config.CfgFuncData{
  82. config.CfgFuncData{"loadImages", loadImages},
  83. config.CfgFuncData{"recovery console", recoveryServices},
  84. })
  85. if err != nil {
  86. log.Fatal(err)
  87. }
  88. }