This repository has been archived by the owner on Oct 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 657
/
recovery.go
105 lines (96 loc) · 2.64 KB
/
recovery.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package recovery
import (
"github.com/rancher/os/config"
"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"
)
var (
// TODO: move this into the os-config file so it can be customised.
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",
},
}
)
func LoadRecoveryConsole(cfg *config.CloudConfig) (*config.CloudConfig, error) {
if cfg.Rancher.Recovery {
Recovery(nil)
}
return cfg, nil
}
func Recovery(initFailure error) {
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{
Nameservers: []string{
"8.8.8.8",
"8.8.4.4",
},
},
},
}
recoveryConfig.Rancher.BootstrapDocker = config.DockerConfig{
EngineOpts: config.EngineOpts{
Bridge: "none",
StorageDriver: "overlay2",
Restart: &[]bool{false}[0],
Graph: "/var/lib/recovery-docker",
Group: "root",
Host: []string{"unix:///var/run/system-docker.sock"},
UserlandProxy: &[]bool{false}[0],
},
}
_, err := docker.Start(&recoveryConfig)
if err != nil {
log.Fatal(err)
}
_, err = config.ChainCfgFuncs(&recoveryConfig,
[]config.CfgFuncData{
{"loadSystemImages", sysinit.LoadBootstrapImages},
{"recovery console", recoveryServices},
})
if err != nil {
log.Fatal(err)
}
}
func recoveryServices(cfg *config.CloudConfig) (*config.CloudConfig, error) {
_, err := compose.RunServiceSet("recovery", cfg, map[string]*composeConfig.ServiceConfigV1{
"recovery": &recoveryDockerService,
})
return nil, err
}