mirror of
https://github.com/rancher/os.git
synced 2025-09-07 09:42:21 +00:00
Mount the boot partition when booting
Also update StateDir and OemDir for better clarity
This commit is contained in:
@@ -560,20 +560,20 @@ func layDownOS(image, installType, cloudConfig, device, partition, statedir, kap
|
|||||||
kernelArgs = kernelArgs + " console=" + CONSOLE
|
kernelArgs = kernelArgs + " console=" + CONSOLE
|
||||||
|
|
||||||
if kappend == "" {
|
if kappend == "" {
|
||||||
preservedAppend, _ := ioutil.ReadFile(filepath.Join(baseName, install.BootDir+"append"))
|
preservedAppend, _ := ioutil.ReadFile(filepath.Join(baseName, config.BootDir, "append"))
|
||||||
kappend = string(preservedAppend)
|
kappend = string(preservedAppend)
|
||||||
} else {
|
} else {
|
||||||
ioutil.WriteFile(filepath.Join(baseName, install.BootDir+"append"), []byte(kappend), 0644)
|
ioutil.WriteFile(filepath.Join(baseName, config.BootDir, "append"), []byte(kappend), 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
if installType == "amazon-ebs-pv" {
|
if installType == "amazon-ebs-pv" {
|
||||||
menu := install.BootVars{
|
menu := install.BootVars{
|
||||||
BaseName: baseName,
|
BaseName: baseName,
|
||||||
BootDir: install.BootDir,
|
BootDir: config.BootDir,
|
||||||
Timeout: 0,
|
Timeout: 0,
|
||||||
Fallback: 0, // need to be conditional on there being a 'rollback'?
|
Fallback: 0, // need to be conditional on there being a 'rollback'?
|
||||||
Entries: []install.MenuEntry{
|
Entries: []install.MenuEntry{
|
||||||
install.MenuEntry{"RancherOS-current", install.BootDir, VERSION, kernelArgs, kappend},
|
install.MenuEntry{"RancherOS-current", config.BootDir, VERSION, kernelArgs, kappend},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
install.PvGrubConfig(menu)
|
install.PvGrubConfig(menu)
|
||||||
@@ -587,7 +587,7 @@ func layDownOS(image, installType, cloudConfig, device, partition, statedir, kap
|
|||||||
log.Debugf("installRancher done")
|
log.Debugf("installRancher done")
|
||||||
|
|
||||||
if kexec {
|
if kexec {
|
||||||
power.Kexec(false, filepath.Join(baseName, install.BootDir), kernelArgs+" "+kappend)
|
power.Kexec(false, filepath.Join(baseName, config.BootDir), kernelArgs+" "+kappend)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -801,7 +801,7 @@ func setBootable(device, diskType string) error {
|
|||||||
func upgradeBootloader(device, baseName, diskType string) error {
|
func upgradeBootloader(device, baseName, diskType string) error {
|
||||||
log.Debugf("start upgradeBootloader")
|
log.Debugf("start upgradeBootloader")
|
||||||
|
|
||||||
grubDir := filepath.Join(baseName, install.BootDir+"grub")
|
grubDir := filepath.Join(baseName, config.BootDir, "grub")
|
||||||
if _, err := os.Stat(grubDir); os.IsNotExist(err) {
|
if _, err := os.Stat(grubDir); os.IsNotExist(err) {
|
||||||
log.Debugf("%s does not exist - no need to upgrade bootloader", grubDir)
|
log.Debugf("%s does not exist - no need to upgrade bootloader", grubDir)
|
||||||
// we've already upgraded
|
// we've already upgraded
|
||||||
@@ -809,12 +809,12 @@ func upgradeBootloader(device, baseName, diskType string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// deal with systems which were previously upgraded, then rolled back, and are now being re-upgraded
|
// deal with systems which were previously upgraded, then rolled back, and are now being re-upgraded
|
||||||
grubBackup := filepath.Join(baseName, install.BootDir+"grub_backup")
|
grubBackup := filepath.Join(baseName, config.BootDir, "grub_backup")
|
||||||
if err := os.RemoveAll(grubBackup); err != nil {
|
if err := os.RemoveAll(grubBackup); err != nil {
|
||||||
log.Errorf("RemoveAll (%s): %s", grubBackup, err)
|
log.Errorf("RemoveAll (%s): %s", grubBackup, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
backupSyslinuxDir := filepath.Join(baseName, install.BootDir+"syslinux_backup")
|
backupSyslinuxDir := filepath.Join(baseName, config.BootDir, "syslinux_backup")
|
||||||
if _, err := os.Stat(backupSyslinuxDir); !os.IsNotExist(err) {
|
if _, err := os.Stat(backupSyslinuxDir); !os.IsNotExist(err) {
|
||||||
backupSyslinuxLdlinuxSys := filepath.Join(backupSyslinuxDir, "ldlinux.sys")
|
backupSyslinuxLdlinuxSys := filepath.Join(backupSyslinuxDir, "ldlinux.sys")
|
||||||
if _, err := os.Stat(backupSyslinuxLdlinuxSys); !os.IsNotExist(err) {
|
if _, err := os.Stat(backupSyslinuxLdlinuxSys); !os.IsNotExist(err) {
|
||||||
@@ -837,7 +837,7 @@ func upgradeBootloader(device, baseName, diskType string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
syslinuxDir := filepath.Join(baseName, install.BootDir+"syslinux")
|
syslinuxDir := filepath.Join(baseName, config.BootDir, "syslinux")
|
||||||
// it seems that v0.5.0 didn't have a syslinux dir, while 0.7 does
|
// it seems that v0.5.0 didn't have a syslinux dir, while 0.7 does
|
||||||
if _, err := os.Stat(syslinuxDir); !os.IsNotExist(err) {
|
if _, err := os.Stat(syslinuxDir); !os.IsNotExist(err) {
|
||||||
if err := os.Rename(syslinuxDir, backupSyslinuxDir); err != nil {
|
if err := os.Rename(syslinuxDir, backupSyslinuxDir); err != nil {
|
||||||
@@ -858,15 +858,15 @@ func upgradeBootloader(device, baseName, diskType string) error {
|
|||||||
|
|
||||||
cfg = strings.Replace(cfg, "current", "previous", -1)
|
cfg = strings.Replace(cfg, "current", "previous", -1)
|
||||||
// TODO consider removing the APPEND line - as the global.cfg should have the same result
|
// TODO consider removing the APPEND line - as the global.cfg should have the same result
|
||||||
ioutil.WriteFile(filepath.Join(baseName, install.BootDir, "linux-current.cfg"), []byte(cfg), 0644)
|
ioutil.WriteFile(filepath.Join(baseName, config.BootDir, "linux-current.cfg"), []byte(cfg), 0644)
|
||||||
|
|
||||||
lines := strings.Split(cfg, "\n")
|
lines := strings.Split(cfg, "\n")
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
line = strings.TrimSpace(line)
|
line = strings.TrimSpace(line)
|
||||||
if strings.HasPrefix(line, "APPEND") {
|
if strings.HasPrefix(line, "APPEND") {
|
||||||
log.Errorf("write new (%s) %s", filepath.Join(baseName, install.BootDir, "global.cfg"), err)
|
log.Errorf("write new (%s) %s", filepath.Join(baseName, config.BootDir, "global.cfg"), err)
|
||||||
// TODO: need to append any extra's the user specified
|
// TODO: need to append any extra's the user specified
|
||||||
ioutil.WriteFile(filepath.Join(baseName, install.BootDir, "global.cfg"), []byte(cfg), 0644)
|
ioutil.WriteFile(filepath.Join(baseName, config.BootDir, "global.cfg"), []byte(cfg), 0644)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -927,7 +927,7 @@ func installSyslinux(device, baseName, diskType string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sysLinuxDir := filepath.Join(baseName, install.BootDir, "syslinux")
|
sysLinuxDir := filepath.Join(baseName, config.BootDir, "syslinux")
|
||||||
if err := os.MkdirAll(sysLinuxDir, 0755); err != nil {
|
if err := os.MkdirAll(sysLinuxDir, 0755); err != nil {
|
||||||
log.Errorf("MkdirAll(%s)): %s", sysLinuxDir, err)
|
log.Errorf("MkdirAll(%s)): %s", sysLinuxDir, err)
|
||||||
//return err
|
//return err
|
||||||
@@ -985,12 +985,12 @@ func installRancher(baseName, VERSION, DIST, kappend string) (string, error) {
|
|||||||
log.Debugf("installRancher")
|
log.Debugf("installRancher")
|
||||||
|
|
||||||
// detect if there already is a linux-current.cfg, if so, move it to linux-previous.cfg,
|
// detect if there already is a linux-current.cfg, if so, move it to linux-previous.cfg,
|
||||||
currentCfg := filepath.Join(baseName, install.BootDir, "linux-current.cfg")
|
currentCfg := filepath.Join(baseName, config.BootDir, "linux-current.cfg")
|
||||||
if _, err := os.Stat(currentCfg); !os.IsNotExist(err) {
|
if _, err := os.Stat(currentCfg); !os.IsNotExist(err) {
|
||||||
existingCfg := filepath.Join(DIST, "linux-current.cfg")
|
existingCfg := filepath.Join(DIST, "linux-current.cfg")
|
||||||
// only remove previous if there is a change to the current
|
// only remove previous if there is a change to the current
|
||||||
if different(currentCfg, existingCfg) {
|
if different(currentCfg, existingCfg) {
|
||||||
previousCfg := filepath.Join(baseName, install.BootDir, "linux-previous.cfg")
|
previousCfg := filepath.Join(baseName, config.BootDir, "linux-previous.cfg")
|
||||||
if _, err := os.Stat(previousCfg); !os.IsNotExist(err) {
|
if _, err := os.Stat(previousCfg); !os.IsNotExist(err) {
|
||||||
if err := os.Remove(previousCfg); err != nil {
|
if err := os.Remove(previousCfg); err != nil {
|
||||||
return currentCfg, err
|
return currentCfg, err
|
||||||
@@ -1012,7 +1012,7 @@ func installRancher(baseName, VERSION, DIST, kappend string) (string, error) {
|
|||||||
if file.Name() == "global.cfg" {
|
if file.Name() == "global.cfg" {
|
||||||
overwrite = false
|
overwrite = false
|
||||||
}
|
}
|
||||||
if err := dfs.CopyFileOverwrite(filepath.Join(DIST, file.Name()), filepath.Join(baseName, install.BootDir), file.Name(), overwrite); err != nil {
|
if err := dfs.CopyFileOverwrite(filepath.Join(DIST, file.Name()), filepath.Join(baseName, config.BootDir), file.Name(), overwrite); err != nil {
|
||||||
log.Errorf("copy %s: %s", file.Name(), err)
|
log.Errorf("copy %s: %s", file.Name(), err)
|
||||||
//return err
|
//return err
|
||||||
}
|
}
|
||||||
@@ -1020,7 +1020,7 @@ func installRancher(baseName, VERSION, DIST, kappend string) (string, error) {
|
|||||||
|
|
||||||
// the general INCLUDE syslinuxcfg
|
// the general INCLUDE syslinuxcfg
|
||||||
isolinuxFile := filepath.Join(DIST, "isolinux", "isolinux.cfg")
|
isolinuxFile := filepath.Join(DIST, "isolinux", "isolinux.cfg")
|
||||||
syslinuxDir := filepath.Join(baseName, install.BootDir, "syslinux")
|
syslinuxDir := filepath.Join(baseName, config.BootDir, "syslinux")
|
||||||
if err := dfs.CopyFileOverwrite(isolinuxFile, syslinuxDir, "syslinux.cfg", true); err != nil {
|
if err := dfs.CopyFileOverwrite(isolinuxFile, syslinuxDir, "syslinux.cfg", true); err != nil {
|
||||||
log.Errorf("copy global syslinux.cfgS%s: %s", "syslinux.cfg", err)
|
log.Errorf("copy global syslinux.cfgS%s: %s", "syslinux.cfg", err)
|
||||||
//return err
|
//return err
|
||||||
@@ -1030,7 +1030,7 @@ func installRancher(baseName, VERSION, DIST, kappend string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The global.cfg INCLUDE - useful for over-riding the APPEND line
|
// The global.cfg INCLUDE - useful for over-riding the APPEND line
|
||||||
globalFile := filepath.Join(filepath.Join(baseName, install.BootDir), "global.cfg")
|
globalFile := filepath.Join(baseName, config.BootDir, "global.cfg")
|
||||||
if _, err := os.Stat(globalFile); !os.IsNotExist(err) {
|
if _, err := os.Stat(globalFile); !os.IsNotExist(err) {
|
||||||
err := ioutil.WriteFile(globalFile, []byte("APPEND "+kappend), 0644)
|
err := ioutil.WriteFile(globalFile, []byte("APPEND "+kappend), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -11,8 +11,6 @@ import (
|
|||||||
"github.com/rancher/os/pkg/util"
|
"github.com/rancher/os/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
const BootDir = "boot/"
|
|
||||||
|
|
||||||
type MenuEntry struct {
|
type MenuEntry struct {
|
||||||
Name, BootDir, Version, KernelArgs, Append string
|
Name, BootDir, Version, KernelArgs, Append string
|
||||||
}
|
}
|
||||||
@@ -53,7 +51,7 @@ func MountDevice(baseName, device, partition string, raw bool) (string, string,
|
|||||||
}
|
}
|
||||||
if d != "" {
|
if d != "" {
|
||||||
partition = d
|
partition = d
|
||||||
baseName = filepath.Join(baseName, BootDir)
|
baseName = filepath.Join(baseName, config.BootDir)
|
||||||
} else {
|
} else {
|
||||||
if dev := util.ResolveDevice(cfg.Rancher.State.Dev); dev != "" {
|
if dev := util.ResolveDevice(cfg.Rancher.State.Dev); dev != "" {
|
||||||
// try the rancher.state.dev setting
|
// try the rancher.state.dev setting
|
||||||
|
@@ -48,16 +48,17 @@ func RunInit() error {
|
|||||||
{"set env", env.Init},
|
{"set env", env.Init},
|
||||||
{"preparefs", prepare.FS},
|
{"preparefs", prepare.FS},
|
||||||
{"save init cmdline", prepare.SaveCmdline},
|
{"save init cmdline", prepare.SaveCmdline},
|
||||||
{"mount OEM", fsmount.OEM},
|
{"mount OEM", fsmount.MountOem},
|
||||||
{"debug save cfg", debug.PrintAndLoadConfig},
|
{"debug save cfg", debug.PrintAndLoadConfig},
|
||||||
{"load modules", modules.LoadModules},
|
{"load modules", modules.LoadModules},
|
||||||
{"recovery console", recovery.LoadRecoveryConsole},
|
{"recovery console", recovery.LoadRecoveryConsole},
|
||||||
{"cloud-init", cloudinit.CloudInit},
|
{"cloud-init", cloudinit.CloudInit},
|
||||||
{"b2d env", b2d.B2D},
|
{"b2d env", b2d.B2D},
|
||||||
{"mount and bootstrap", fsmount.MountAndBootstrap},
|
{"mount STATE and bootstrap", fsmount.MountStateAndBootstrap},
|
||||||
{"read cfg and log files", configfiles.ReadConfigFiles},
|
{"read cfg and log files", configfiles.ReadConfigFiles},
|
||||||
{"switchroot", switchroot.SwitchRoot},
|
{"switchroot", switchroot.SwitchRoot},
|
||||||
{"mount OEM2", fsmount.OEM},
|
{"mount OEM2", fsmount.MountOem},
|
||||||
|
{"mount BOOT", fsmount.MountBoot},
|
||||||
{"write cfg and log files", configfiles.WriteConfigFiles},
|
{"write cfg and log files", configfiles.WriteConfigFiles},
|
||||||
{"hypervisor Env", hypervisor.Env},
|
{"hypervisor Env", hypervisor.Env},
|
||||||
{"b2d Env", b2d.Env},
|
{"b2d Env", b2d.Env},
|
||||||
|
@@ -178,7 +178,7 @@ func reboot(name string, force bool, code uint) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer util.Unmount(baseName)
|
defer util.Unmount(baseName)
|
||||||
Kexec(previouskexecFlag, filepath.Join(baseName, install.BootDir), kexecAppendFlag)
|
Kexec(previouskexecFlag, filepath.Join(baseName, config.BootDir), kexecAppendFlag)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
368
config/schema.go
368
config/schema.go
@@ -1,209 +1,211 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
var schema = `{
|
var schema = `{
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
|
|
||||||
"properties": {
|
"properties": {
|
||||||
"ssh_authorized_keys": {"$ref": "#/definitions/list_of_strings"},
|
"ssh_authorized_keys": {"$ref": "#/definitions/list_of_strings"},
|
||||||
"write_files": {
|
"write_files": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {"$ref": "#/definitions/file_config"}
|
"items": {"$ref": "#/definitions/file_config"}
|
||||||
},
|
},
|
||||||
"hostname": {"type": "string"},
|
"hostname": {"type": "string"},
|
||||||
"mounts": {"type": "array"},
|
"mounts": {"type": "array"},
|
||||||
"rancher": {"$ref": "#/definitions/rancher_config"},
|
"rancher": {"$ref": "#/definitions/rancher_config"},
|
||||||
"runcmd": {"type": "array"},
|
"runcmd": {"type": "array"},
|
||||||
"bootcmd": {"type": "array"}
|
"bootcmd": {"type": "array"}
|
||||||
},
|
},
|
||||||
|
|
||||||
"definitions": {
|
"definitions": {
|
||||||
"rancher_config": {
|
"rancher_config": {
|
||||||
"id": "#/definitions/rancher_config",
|
"id": "#/definitions/rancher_config",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
|
|
||||||
"properties": {
|
"properties": {
|
||||||
"console": {"type": "string"},
|
"console": {"type": "string"},
|
||||||
"environment": {"type": "object"},
|
"environment": {"type": "object"},
|
||||||
"cloud_init_services": {"type": "object"},
|
"cloud_init_services": {"type": "object"},
|
||||||
"services": {"type": "object"},
|
"services": {"type": "object"},
|
||||||
"bootstrap": {"type": "object"},
|
"bootstrap": {"type": "object"},
|
||||||
"autoformat": {"type": "object"},
|
"autoformat": {"type": "object"},
|
||||||
"bootstrap_docker": {"$ref": "#/definitions/docker_config"},
|
"bootstrap_docker": {"$ref": "#/definitions/docker_config"},
|
||||||
"cloud_init": {"$ref": "#/definitions/cloud_init_config"},
|
"cloud_init": {"$ref": "#/definitions/cloud_init_config"},
|
||||||
"debug": {"type": "boolean"},
|
"debug": {"type": "boolean"},
|
||||||
"rm_usr": {"type": "boolean"},
|
"rm_usr": {"type": "boolean"},
|
||||||
"no_sharedroot": {"type": "boolean"},
|
"no_sharedroot": {"type": "boolean"},
|
||||||
"log": {"type": "boolean"},
|
"log": {"type": "boolean"},
|
||||||
"force_console_rebuild": {"type": "boolean"},
|
"force_console_rebuild": {"type": "boolean"},
|
||||||
"recovery": {"type": "boolean"},
|
"recovery": {"type": "boolean"},
|
||||||
"disable": {"$ref": "#/definitions/list_of_strings"},
|
"disable": {"$ref": "#/definitions/list_of_strings"},
|
||||||
"services_include": {"type": "object"},
|
"services_include": {"type": "object"},
|
||||||
"modules": {"$ref": "#/definitions/list_of_strings"},
|
"modules": {"$ref": "#/definitions/list_of_strings"},
|
||||||
"network": {"$ref": "#/definitions/network_config"},
|
"network": {"$ref": "#/definitions/network_config"},
|
||||||
"default_network": {"type": "object"},
|
"default_network": {"type": "object"},
|
||||||
"repositories": {"type": "object"},
|
"repositories": {"type": "object"},
|
||||||
"ssh": {"$ref": "#/definitions/ssh_config"},
|
"ssh": {"$ref": "#/definitions/ssh_config"},
|
||||||
"state": {"$ref": "#/definitions/state_config"},
|
"state": {"$ref": "#/definitions/state_config"},
|
||||||
"system_docker": {"$ref": "#/definitions/docker_config"},
|
"system_docker": {"$ref": "#/definitions/docker_config"},
|
||||||
"upgrade": {"$ref": "#/definitions/upgrade_config"},
|
"upgrade": {"$ref": "#/definitions/upgrade_config"},
|
||||||
"docker": {"$ref": "#/definitions/docker_config"},
|
"docker": {"$ref": "#/definitions/docker_config"},
|
||||||
"registry_auths": {"type": "object"},
|
"registry_auths": {"type": "object"},
|
||||||
"defaults": {"$ref": "#/definitions/defaults_config"},
|
"defaults": {"$ref": "#/definitions/defaults_config"},
|
||||||
"resize_device": {"type": "string"},
|
"resize_device": {"type": "string"},
|
||||||
"sysctl": {"type": "object"},
|
"sysctl": {"type": "object"},
|
||||||
"restart_services": {"type": "array"},
|
"restart_services": {"type": "array"},
|
||||||
"hypervisor_service": {"type": "boolean"},
|
"hypervisor_service": {"type": "boolean"},
|
||||||
"shutdown_timeout": {"type": "integer"},
|
"shutdown_timeout": {"type": "integer"},
|
||||||
"preload_wait": {"type": "boolean"}
|
"preload_wait": {"type": "boolean"}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"file_config": {
|
"file_config": {
|
||||||
"id": "#/definitions/file_config",
|
"id": "#/definitions/file_config",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
|
|
||||||
"properties": {
|
"properties": {
|
||||||
"encoding": {"type": "string"},
|
"encoding": {"type": "string"},
|
||||||
"container": {"type": "string"},
|
"container": {"type": "string"},
|
||||||
"content": {"type": "string"},
|
"content": {"type": "string"},
|
||||||
"owner": {"type": "string"},
|
"owner": {"type": "string"},
|
||||||
"path": {"type": "string"},
|
"path": {"type": "string"},
|
||||||
"permissions": {"type": "string"}
|
"permissions": {"type": "string"}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"network_config": {
|
"network_config": {
|
||||||
"id": "#/definitions/network_config",
|
"id": "#/definitions/network_config",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
|
|
||||||
"properties": {
|
"properties": {
|
||||||
"pre_cmds": {"$ref": "#/definitions/list_of_strings"},
|
"pre_cmds": {"$ref": "#/definitions/list_of_strings"},
|
||||||
"dns": {"type": "object"},
|
"dns": {"type": "object"},
|
||||||
"interfaces": {"type": "object"},
|
"interfaces": {"type": "object"},
|
||||||
"post_cmds": {"$ref": "#/definitions/list_of_strings"},
|
"post_cmds": {"$ref": "#/definitions/list_of_strings"},
|
||||||
"http_proxy": {"type": "string"},
|
"http_proxy": {"type": "string"},
|
||||||
"https_proxy": {"type": "string"},
|
"https_proxy": {"type": "string"},
|
||||||
"no_proxy": {"type": "string"}
|
"no_proxy": {"type": "string"}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"upgrade_config": {
|
"upgrade_config": {
|
||||||
"id": "#/definitions/upgrade_config",
|
"id": "#/definitions/upgrade_config",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
|
|
||||||
"properties": {
|
"properties": {
|
||||||
"url": {"type": "string"},
|
"url": {"type": "string"},
|
||||||
"image": {"type": "string"},
|
"image": {"type": "string"},
|
||||||
"rollback": {"type": "string"}
|
"rollback": {"type": "string"}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"docker_config": {
|
"docker_config": {
|
||||||
"id": "#/definitions/docker_config",
|
"id": "#/definitions/docker_config",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
|
|
||||||
"properties": {
|
"properties": {
|
||||||
"engine": {"type": "string"},
|
"engine": {"type": "string"},
|
||||||
"tls": {"type": "boolean"},
|
"tls": {"type": "boolean"},
|
||||||
"tls_args": {"$ref": "#/definitions/list_of_strings"},
|
"tls_args": {"$ref": "#/definitions/list_of_strings"},
|
||||||
"args": {"$ref": "#/definitions/list_of_strings"},
|
"args": {"$ref": "#/definitions/list_of_strings"},
|
||||||
"extra_args": {"$ref": "#/definitions/list_of_strings"},
|
"extra_args": {"$ref": "#/definitions/list_of_strings"},
|
||||||
"server_cert": {"type": "string"},
|
"server_cert": {"type": "string"},
|
||||||
"server_key": {"type": "string"},
|
"server_key": {"type": "string"},
|
||||||
"ca_cert": {"type": "string"},
|
"ca_cert": {"type": "string"},
|
||||||
"ca_key": {"type": "string"},
|
"ca_key": {"type": "string"},
|
||||||
"environment": {"$ref": "#/definitions/list_of_strings"},
|
"environment": {"$ref": "#/definitions/list_of_strings"},
|
||||||
"storage_context": {"type": "string"},
|
"storage_context": {"type": "string"},
|
||||||
"exec": {"type": ["boolean", "null"]},
|
"exec": {"type": ["boolean", "null"]},
|
||||||
"bridge": {"type": "string"},
|
"bridge": {"type": "string"},
|
||||||
"bip": {"type": "string"},
|
"bip": {"type": "string"},
|
||||||
"config_file": {"type": "string"},
|
"config_file": {"type": "string"},
|
||||||
"containerd": {"type": "string"},
|
"containerd": {"type": "string"},
|
||||||
"debug": {"type": ["boolean", "null"]},
|
"debug": {"type": ["boolean", "null"]},
|
||||||
"exec_root": {"type": "string"},
|
"exec_root": {"type": "string"},
|
||||||
"group": {"type": "string"},
|
"group": {"type": "string"},
|
||||||
"graph": {"type": "string"},
|
"graph": {"type": "string"},
|
||||||
"host": {"type": "array"},
|
"host": {"type": "array"},
|
||||||
"live_restore": {"type": ["boolean", "null"]},
|
"live_restore": {"type": ["boolean", "null"]},
|
||||||
"log_driver": {"type": "string"},
|
"log_driver": {"type": "string"},
|
||||||
"log_opts": {"type": "object"},
|
"log_opts": {"type": "object"},
|
||||||
"pid_file": {"type": "string"},
|
"pid_file": {"type": "string"},
|
||||||
"registry_mirror": {"type": "string"},
|
"registry_mirror": {"type": "string"},
|
||||||
"restart": {"type": ["boolean", "null"]},
|
"restart": {"type": ["boolean", "null"]},
|
||||||
"selinux_enabled": {"type": ["boolean", "null"]},
|
"selinux_enabled": {"type": ["boolean", "null"]},
|
||||||
"storage_driver": {"type": "string"},
|
"storage_driver": {"type": "string"},
|
||||||
"userland_proxy": {"type": ["boolean", "null"]},
|
"userland_proxy": {"type": ["boolean", "null"]},
|
||||||
"insecure_registry": {"$ref": "#/definitions/list_of_strings"}
|
"insecure_registry": {"$ref": "#/definitions/list_of_strings"}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"ssh_config": {
|
"ssh_config": {
|
||||||
"id": "#/definitions/ssh_config",
|
"id": "#/definitions/ssh_config",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
|
|
||||||
"properties": {
|
"properties": {
|
||||||
"keys": {"type": "object"},
|
"keys": {"type": "object"},
|
||||||
"daemon": {"type": "boolean"},
|
"daemon": {"type": "boolean"},
|
||||||
"port": {"type": "integer"},
|
"port": {"type": "integer"},
|
||||||
"listen_address": {"type": "string"}
|
"listen_address": {"type": "string"}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"state_config": {
|
"state_config": {
|
||||||
"id": "#/definitions/state_config",
|
"id": "#/definitions/state_config",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
|
|
||||||
"properties": {
|
"properties": {
|
||||||
"directory": {"type": "string"},
|
"directory": {"type": "string"},
|
||||||
"fstype": {"type": "string"},
|
"fstype": {"type": "string"},
|
||||||
"dev": {"type": "string"},
|
"dev": {"type": "string"},
|
||||||
"wait": {"type": "boolean"},
|
"wait": {"type": "boolean"},
|
||||||
"required": {"type": "boolean"},
|
"required": {"type": "boolean"},
|
||||||
"autoformat": {"$ref": "#/definitions/list_of_strings"},
|
"autoformat": {"$ref": "#/definitions/list_of_strings"},
|
||||||
"mdadm_scan": {"type": "boolean"},
|
"mdadm_scan": {"type": "boolean"},
|
||||||
"rngd": {"type": "boolean"},
|
"rngd": {"type": "boolean"},
|
||||||
"script": {"type": "string"},
|
"script": {"type": "string"},
|
||||||
"oem_fstype": {"type": "string"},
|
"oem_fstype": {"type": "string"},
|
||||||
"oem_dev": {"type": "string"}
|
"oem_dev": {"type": "string"},
|
||||||
}
|
"boot_fstype": {"type": "string"},
|
||||||
},
|
"boot_dev": {"type": "string"}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
"cloud_init_config": {
|
"cloud_init_config": {
|
||||||
"id": "#/definitions/cloud_init_config",
|
"id": "#/definitions/cloud_init_config",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
|
|
||||||
"properties": {
|
"properties": {
|
||||||
"datasources": {"$ref": "#/definitions/list_of_strings"}
|
"datasources": {"$ref": "#/definitions/list_of_strings"}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"defaults_config": {
|
"defaults_config": {
|
||||||
"id": "#/definitions/defaults_config",
|
"id": "#/definitions/defaults_config",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
|
|
||||||
"properties": {
|
"properties": {
|
||||||
"hostname": {"type": "string"},
|
"hostname": {"type": "string"},
|
||||||
"docker": {"type": "object"},
|
"docker": {"type": "object"},
|
||||||
"network": {"$ref": "#/definitions/network_config"}
|
"network": {"$ref": "#/definitions/network_config"}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"list_of_strings": {
|
"list_of_strings": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {"type": "string"},
|
"items": {"type": "string"},
|
||||||
"uniqueItems": true
|
"uniqueItems": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
`
|
`
|
||||||
|
@@ -12,7 +12,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
OEM = "/usr/share/ros/oem"
|
OemDir = "/usr/share/ros/oem"
|
||||||
|
BootDir = "/boot"
|
||||||
|
StateDir = "/state"
|
||||||
RosBin = "/usr/bin/ros"
|
RosBin = "/usr/bin/ros"
|
||||||
SysInitBin = "/usr/bin/ros-sysinit"
|
SysInitBin = "/usr/bin/ros-sysinit"
|
||||||
SystemDockerHost = "unix:///var/run/system-docker.sock"
|
SystemDockerHost = "unix:///var/run/system-docker.sock"
|
||||||
@@ -47,11 +49,10 @@ const (
|
|||||||
EtcResolvConfFile = "/etc/resolv.conf"
|
EtcResolvConfFile = "/etc/resolv.conf"
|
||||||
MultiDockerConfFile = "/var/lib/rancher/conf.d/m-user-docker.yml"
|
MultiDockerConfFile = "/var/lib/rancher/conf.d/m-user-docker.yml"
|
||||||
MultiDockerDataDir = "/var/lib/m-user-docker"
|
MultiDockerDataDir = "/var/lib/m-user-docker"
|
||||||
State = "/state"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
OemConfigFile = OEM + "/oem-config.yml"
|
OemConfigFile = OemDir + "/oem-config.yml"
|
||||||
Version string
|
Version string
|
||||||
BuildDate string
|
BuildDate string
|
||||||
Arch string
|
Arch string
|
||||||
@@ -205,6 +206,8 @@ type StateConfig struct {
|
|||||||
Script string `yaml:"script,omitempty"`
|
Script string `yaml:"script,omitempty"`
|
||||||
OemFsType string `yaml:"oem_fstype,omitempty"`
|
OemFsType string `yaml:"oem_fstype,omitempty"`
|
||||||
OemDev string `yaml:"oem_dev,omitempty"`
|
OemDev string `yaml:"oem_dev,omitempty"`
|
||||||
|
BootFsType string `yaml:"boot_fstype,omitempty"`
|
||||||
|
BootDev string `yaml:"boot_dev,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CloudInit struct {
|
type CloudInit struct {
|
||||||
|
@@ -82,6 +82,8 @@ rancher:
|
|||||||
fstype: auto
|
fstype: auto
|
||||||
oem_fstype: auto
|
oem_fstype: auto
|
||||||
oem_dev: LABEL=RANCHER_OEM
|
oem_dev: LABEL=RANCHER_OEM
|
||||||
|
boot_fstype: auto
|
||||||
|
boot_dev: LABEL=RANCHER_BOOT
|
||||||
rngd: true
|
rngd: true
|
||||||
sysctl:
|
sysctl:
|
||||||
fs.file-max: 1000000000
|
fs.file-max: 1000000000
|
||||||
|
@@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func CloudInit(cfg *config.CloudConfig) (*config.CloudConfig, error) {
|
func CloudInit(cfg *config.CloudConfig) (*config.CloudConfig, error) {
|
||||||
cfg.Rancher.CloudInit.Datasources = config.LoadConfigWithPrefix(config.State).Rancher.CloudInit.Datasources
|
cfg.Rancher.CloudInit.Datasources = config.LoadConfigWithPrefix(config.StateDir).Rancher.CloudInit.Datasources
|
||||||
hypervisor := util.GetHypervisor()
|
hypervisor := util.GetHypervisor()
|
||||||
if hypervisor == "" {
|
if hypervisor == "" {
|
||||||
log.Infof("ros init: No Detected Hypervisor")
|
log.Infof("ros init: No Detected Hypervisor")
|
||||||
|
@@ -86,7 +86,7 @@ func WriteConfigFiles(cfg *config.CloudConfig) (*config.CloudConfig, error) {
|
|||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
log.FsReady()
|
log.FsReady()
|
||||||
log.Debugf("WARNING: switchroot and mount OEM2 phases not written to log file")
|
log.Debugf("WARNING: switchroot and mount OEM2 and BOOT phases not written to log file")
|
||||||
|
|
||||||
return cfg, nil
|
return cfg, nil
|
||||||
}
|
}
|
||||||
|
@@ -19,15 +19,27 @@ var (
|
|||||||
ShouldSwitchRoot bool
|
ShouldSwitchRoot bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func OEM(cfg *config.CloudConfig) (*config.CloudConfig, error) {
|
func MountOem(cfg *config.CloudConfig) (*config.CloudConfig, error) {
|
||||||
if cfg == nil {
|
if err := mountConfigured("oem", cfg.Rancher.State.OemDev, cfg.Rancher.State.OemFsType, config.OemDir); err != nil {
|
||||||
cfg = config.LoadConfig()
|
|
||||||
}
|
|
||||||
if err := mountConfigured("oem", cfg.Rancher.State.OemDev, cfg.Rancher.State.OemFsType, config.OEM); err != nil {
|
|
||||||
log.Debugf("Not mounting OEM: %v", err)
|
log.Debugf("Not mounting OEM: %v", err)
|
||||||
} else {
|
} else {
|
||||||
log.Infof("Mounted OEM: %s", cfg.Rancher.State.OemDev)
|
log.Infof("Mounted OEM: %s", cfg.Rancher.State.OemDev)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return cfg, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func MountBoot(cfg *config.CloudConfig) (*config.CloudConfig, error) {
|
||||||
|
if IsInitrd() {
|
||||||
|
return cfg, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := mountConfigured("boot", cfg.Rancher.State.BootDev, cfg.Rancher.State.BootFsType, config.BootDir); err != nil {
|
||||||
|
log.Debugf("Not mounting BOOT: %v", err)
|
||||||
|
} else {
|
||||||
|
log.Infof("Mounted BOOT: %s", cfg.Rancher.State.BootDev)
|
||||||
|
}
|
||||||
|
|
||||||
return cfg, nil
|
return cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +68,7 @@ func mountConfigured(display, dev, fsType, target string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func mountState(cfg *config.CloudConfig) error {
|
func mountState(cfg *config.CloudConfig) error {
|
||||||
return mountConfigured("state", cfg.Rancher.State.Dev, cfg.Rancher.State.FsType, config.State)
|
return mountConfigured("state", cfg.Rancher.State.Dev, cfg.Rancher.State.FsType, config.StateDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
func tryMountState(cfg *config.CloudConfig) error {
|
func tryMountState(cfg *config.CloudConfig) error {
|
||||||
@@ -74,7 +86,7 @@ func tryMountState(cfg *config.CloudConfig) error {
|
|||||||
return mountState(cfg)
|
return mountState(cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func tryMountAndBootstrap(cfg *config.CloudConfig) (*config.CloudConfig, bool, error) {
|
func tryMountStateAndBootstrap(cfg *config.CloudConfig) (*config.CloudConfig, bool, error) {
|
||||||
if !IsInitrd() || cfg.Rancher.State.Dev == "" {
|
if !IsInitrd() || cfg.Rancher.State.Dev == "" {
|
||||||
return cfg, false, nil
|
return cfg, false, nil
|
||||||
}
|
}
|
||||||
@@ -94,9 +106,9 @@ func IsInitrd() bool {
|
|||||||
return int64(stat.Type) == tmpfsMagic || int64(stat.Type) == ramfsMagic
|
return int64(stat.Type) == tmpfsMagic || int64(stat.Type) == ramfsMagic
|
||||||
}
|
}
|
||||||
|
|
||||||
func MountAndBootstrap(cfg *config.CloudConfig) (*config.CloudConfig, error) {
|
func MountStateAndBootstrap(cfg *config.CloudConfig) (*config.CloudConfig, error) {
|
||||||
var err error
|
var err error
|
||||||
cfg, ShouldSwitchRoot, err = tryMountAndBootstrap(cfg)
|
cfg, ShouldSwitchRoot, err = tryMountStateAndBootstrap(cfg)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@@ -19,8 +19,8 @@ func SwitchRoot(cfg *config.CloudConfig) (*config.CloudConfig, error) {
|
|||||||
if !fsmount.ShouldSwitchRoot {
|
if !fsmount.ShouldSwitchRoot {
|
||||||
return cfg, nil
|
return cfg, nil
|
||||||
}
|
}
|
||||||
log.Debugf("Switching to new root at %s %s", config.State, cfg.Rancher.State.Directory)
|
log.Debugf("Switching to new root at %s %s", config.StateDir, cfg.Rancher.State.Directory)
|
||||||
if err := switchRoot(config.State, cfg.Rancher.State.Directory, cfg.Rancher.RmUsr); err != nil {
|
if err := switchRoot(config.StateDir, cfg.Rancher.State.Directory, cfg.Rancher.RmUsr); err != nil {
|
||||||
return cfg, err
|
return cfg, err
|
||||||
}
|
}
|
||||||
return cfg, nil
|
return cfg, nil
|
||||||
@@ -112,7 +112,7 @@ func copyMoveRoot(rootfs string, rmUsr bool) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func switchRoot(rootfs, subdir string, rmUsr bool) error {
|
func switchRoot(rootfs, subdir string, rmUsr bool) error {
|
||||||
if err := syscall.Unmount(config.OEM, 0); err != nil {
|
if err := syscall.Unmount(config.OemDir, 0); err != nil {
|
||||||
log.Debugf("Not umounting OEM: %v", err)
|
log.Debugf("Not umounting OEM: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -22,7 +22,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func hasImage(name string) bool {
|
func hasImage(name string) bool {
|
||||||
stamp := path.Join(config.State, name)
|
stamp := path.Join(config.StateDir, name)
|
||||||
if _, err := os.Stat(stamp); os.IsNotExist(err) {
|
if _, err := os.Stat(stamp); os.IsNotExist(err) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user