1
0
mirror of https://github.com/rancher/os.git synced 2025-07-31 06:32:09 +00:00

try mount state

run bootstrap if failed (and autoformat if we can), then try again
This commit is contained in:
Ivan Mikushin 2015-07-22 21:14:39 +05:00
parent 890052273e
commit ca54b617a0
2 changed files with 31 additions and 15 deletions

View File

@ -68,10 +68,6 @@ func stopDocker(c chan interface{}) error {
}
func bootstrap(cfg *config.Config) error {
if util.ResolveDevice(cfg.State.Dev) != "" {
return nil
}
log.Info("Launching Bootstrap Docker")
c, err := startDocker(cfg)
if err != nil {

View File

@ -249,11 +249,21 @@ func MainInit() {
}
}
func mountStateTmpfs(cfg *config.Config) error {
log.Debugf("State will not be persisted")
return util.Mount("none", STATE, "tmpfs", "")
}
func mountState(cfg *config.Config) error {
var err error
if cfg.State.Dev != "" {
dev := util.ResolveDevice(cfg.State.Dev)
if dev == "" {
msg := fmt.Sprintf("Could not resolve device %q", cfg.State.Dev)
log.Infof(msg)
return fmt.Errorf(msg)
}
log.Infof("Mounting state device %s to %s", dev, STATE)
fsType := cfg.State.FsType
@ -265,20 +275,31 @@ func mountState(cfg *config.Config) error {
log.Debugf("FsType has been set to %s", fsType)
err = util.Mount(dev, STATE, fsType, "")
}
}
if err != nil && cfg.State.Required {
return err
}
if err != nil || cfg.State.Dev == "" {
log.Debugf("State will not be persisted")
err = util.Mount("none", STATE, "tmpfs", "")
} else {
return mountStateTmpfs(cfg)
}
return err
}
func tryMountAndBootstrap(cfg *config.Config) error {
if err := mountState(cfg); err != nil {
if err := bootstrap(cfg); err != nil {
if cfg.State.Required {
return err
}
return mountStateTmpfs(cfg)
}
if err := mountState(cfg); err != nil {
if cfg.State.Required {
return err
}
return mountStateTmpfs(cfg)
}
}
return nil
}
func createGroups(cfg *config.Config) error {
return ioutil.WriteFile("/etc/group", []byte("root:x:0:\n"), 0644)
}
@ -354,8 +375,7 @@ func RunInit() error {
loadModules,
setResolvConf,
setupSystemBridge,
bootstrap,
mountState,
tryMountAndBootstrap,
func(cfg *config.Config) error {
return cfg.Reload()
},