diff --git a/config/types.go b/config/types.go index 3c4e8aca..3bb5381e 100644 --- a/config/types.go +++ b/config/types.go @@ -78,6 +78,7 @@ type RancherConfig struct { BootstrapDocker DockerConfig `yaml:"bootstrap_docker,omitempty"` CloudInit CloudInit `yaml:"cloud_init,omitempty"` Debug bool `yaml:"debug,omitempty"` + RmUsr bool `yaml:"rm_usr,omitempty"` Log bool `yaml:"log,omitempty"` Disable []string `yaml:"disable,omitempty"` ServicesInclude map[string]bool `yaml:"services_include,omitempty"` diff --git a/init/init.go b/init/init.go index bb437832..5fc1a252 100644 --- a/init/init.go +++ b/init/init.go @@ -129,7 +129,7 @@ func tryMountAndBootstrap(cfg *config.CloudConfig) (*config.CloudConfig, error) } log.Debugf("Switching to new root at %s", STATE) - return cfg, switchRoot(STATE) + return cfg, switchRoot(STATE, cfg.Rancher.RmUsr) } func getLaunchConfig(cfg *config.CloudConfig, dockerCfg *config.DockerConfig) (*dockerlaunch.Config, []string) { diff --git a/init/root.go b/init/root.go index 5b9407d8..0c90a853 100644 --- a/init/root.go +++ b/init/root.go @@ -5,7 +5,6 @@ import ( "io/ioutil" "os" "path" - "strings" "syscall" log "github.com/Sirupsen/logrus" @@ -31,15 +30,6 @@ func cleanupTarget(rootfs, targetUsr, usr, usrVer, tmpDir string) (bool, error) log.Errorf("Failed to cleanup temp directory %s: %v", tmpDir, err) } - if strings.HasSuffix(usrVer, "dev") { - log.Debugf("Deleteing old usr: %s", usr) - if err := os.RemoveAll(usr); err != nil { - // Don't care if this fails - log.Errorf("Failed to remove %s: %v", usr, err) - } - return true, nil - } - if _, err := os.Stat(usr); err == nil { return false, nil } @@ -47,12 +37,20 @@ func cleanupTarget(rootfs, targetUsr, usr, usrVer, tmpDir string) (bool, error) return true, nil } -func copyMoveRoot(rootfs string) error { +func copyMoveRoot(rootfs string, rmUsr bool) error { usrVer := fmt.Sprintf("usr-%s", config.VERSION) usr := path.Join(rootfs, usrVer) targetUsr := path.Join(rootfs, "usr") tmpDir := path.Join(rootfs, "tmp") + if rmUsr { + log.Warnf("Development setup. Removing old usr: %s", usr) + if err := os.RemoveAll(usr); err != nil { + // Don't care if this fails + log.Errorf("Failed to remove %s: %v", usr, err) + } + } + if cont, err := cleanupTarget(rootfs, targetUsr, usr, usrVer, tmpDir); !cont { return err } @@ -100,7 +98,7 @@ func copyMoveRoot(rootfs string) error { return nil } -func switchRoot(rootfs string) error { +func switchRoot(rootfs string, rmUsr bool) error { for _, i := range []string{"/dev", "/sys", "/proc", "/run"} { log.Debugf("Moving mount %s to %s", i, path.Join(rootfs, i)) if err := os.MkdirAll(path.Join(rootfs, i), 0755); err != nil { @@ -111,7 +109,7 @@ func switchRoot(rootfs string) error { } } - if err := copyMoveRoot(rootfs); err != nil { + if err := copyMoveRoot(rootfs, rmUsr); err != nil { return err } diff --git a/scripts/run b/scripts/run index 08a860b7..d91f7747 100755 --- a/scripts/run +++ b/scripts/run @@ -13,6 +13,7 @@ INITRD=${BASE}/dist/artifacts/initrd QEMU=1 FORMAT=1 +RM_USR=1 REBUILD=1 while [ "$#" -gt 0 ]; do @@ -54,6 +55,9 @@ while [ "$#" -gt 0 ]; do --no-format) FORMAT=0 ;; + --no-rm-usr) + RM_USR=0 + ;; --no-rebuild) REBUILD=0 ;; @@ -110,6 +114,9 @@ KERNEL_ARGS="quiet rancher.password=rancher console=ttyS0 ${QEMU_APPEND}" if [ "$FORMAT" == "1" ]; then KERNEL_ARGS="${KERNEL_ARGS} rancher.state.formatzero=true rancher.state.autoformat=[/dev/sda,/dev/vda]" fi +if [ "$RM_USR" == "1" ]; then + KERNEL_ARGS="${KERNEL_ARGS} rancher.rm_usr" +fi if [ "$KVM" == "" ] && [ -c /dev/kvm ] && [ -r /dev/kvm ] && [ -w /dev/kvm ]; then KVM=1