1
0
mirror of https://github.com/rancher/os.git synced 2025-07-15 15:51:36 +00:00
os/pkg/init/recovery/recovery.go

106 lines
2.6 KiB
Go
Raw Normal View History

2018-09-16 04:55:26 +00:00
package recovery
2016-11-30 01:06:23 +00:00
import (
"github.com/rancher/os/config"
2018-09-16 04:55:26 +00:00
"github.com/rancher/os/pkg/compose"
"github.com/rancher/os/pkg/init/docker"
"github.com/rancher/os/pkg/log"
"github.com/rancher/os/pkg/netconf"
"github.com/rancher/os/pkg/sysinit"
composeConfig "github.com/docker/libcompose/config"
"github.com/docker/libcompose/yaml"
2016-11-30 01:06:23 +00:00
)
var (
// TODO: move this into the os-config file so it can be customised.
2016-11-30 01:06:23 +00:00
recoveryDockerService = composeConfig.ServiceConfigV1{
Image: config.OsBase,
Command: yaml.Command{
"ros",
"recovery-init",
},
Labels: map[string]string{
config.DetachLabel: "false",
config.ScopeLabel: "system",
},
LogDriver: "json-file",
Net: "host",
Uts: "host",
Pid: "host",
Ipc: "host",
Privileged: true,
Volumes: []string{
"/dev:/host/dev",
"/etc/ssl/certs/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt.rancher",
"/lib/modules:/lib/modules",
"/lib/firmware:/lib/firmware",
"/usr/bin/ros:/usr/bin/ros:ro",
"/usr/bin/ros:/usr/bin/cloud-init-save",
"/usr/bin/ros:/usr/bin/respawn:ro",
"/usr/share/ros:/usr/share/ros:ro",
"/var/lib/rancher:/var/lib/rancher",
"/var/lib/rancher/conf:/var/lib/rancher/conf",
"/var/run:/var/run",
2016-11-30 01:06:23 +00:00
},
}
)
2018-09-16 04:55:26 +00:00
func LoadRecoveryConsole(cfg *config.CloudConfig) (*config.CloudConfig, error) {
if cfg.Rancher.Recovery {
Recovery(nil)
}
return cfg, nil
2016-11-30 01:06:23 +00:00
}
2018-09-16 04:55:26 +00:00
func Recovery(initFailure error) {
2016-11-30 01:06:23 +00:00
if initFailure != nil {
log.Errorf("RancherOS has failed to boot: %v", initFailure)
}
log.Info("Launching recovery console")
var recoveryConfig config.CloudConfig
recoveryConfig.Rancher.Defaults = config.Defaults{
Network: netconf.NetworkConfig{
DNS: netconf.DNSConfig{
2016-11-30 01:06:23 +00:00
Nameservers: []string{
"8.8.8.8",
"8.8.4.4",
},
},
},
}
recoveryConfig.Rancher.BootstrapDocker = config.DockerConfig{
EngineOpts: config.EngineOpts{
Bridge: "none",
2018-11-01 06:39:09 +00:00
StorageDriver: "overlay2",
2016-11-30 01:06:23 +00:00
Restart: &[]bool{false}[0],
Graph: "/var/lib/recovery-docker",
Group: "root",
Host: []string{"unix:///var/run/system-docker.sock"},
UserlandProxy: &[]bool{false}[0],
},
}
2018-09-16 04:55:26 +00:00
_, err := docker.Start(&recoveryConfig)
2016-11-30 01:06:23 +00:00
if err != nil {
log.Fatal(err)
}
_, err = config.ChainCfgFuncs(&recoveryConfig,
[]config.CfgFuncData{
2018-11-01 06:39:09 +00:00
{"loadSystemImages", sysinit.LoadBootstrapImages},
2018-09-16 04:55:26 +00:00
{"recovery console", recoveryServices},
})
2016-11-30 01:06:23 +00:00
if err != nil {
log.Fatal(err)
}
}
2018-09-16 04:55:26 +00:00
func recoveryServices(cfg *config.CloudConfig) (*config.CloudConfig, error) {
_, err := compose.RunServiceSet("recovery", cfg, map[string]*composeConfig.ServiceConfigV1{
"recovery": &recoveryDockerService,
})
return nil, err
}