1
0
mirror of https://github.com/rancher/os.git synced 2025-08-02 07:24:28 +00:00

remove dependency on version string

using rancher.rm_usr kernel param instead
This commit is contained in:
Ivan Mikushin 2015-10-06 18:41:04 +05:00
parent 4899ccd89c
commit c79a64e42e
4 changed files with 20 additions and 14 deletions

View File

@ -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"`

View File

@ -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) {

View File

@ -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
}

View File

@ -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