コード例 #1
0
ファイル: init.go プロジェクト: beibei1990/os
func mountState(cfg *config.Config) error {
	var err error

	if cfg.State.Dev != "" {
		dev := util.ResolveDevice(cfg.State.Dev)
		log.Infof("Mounting state device %s to %s", dev, STATE)

		fsType := cfg.State.FsType
		if fsType == "auto" {
			fsType, err = util.GetFsType(dev)
		}

		if err == nil {
			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", "")
	}

	return err
}
コード例 #2
0
ファイル: init.go プロジェクト: slashk/os
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
		if fsType == "auto" {
			fsType, err = util.GetFsType(dev)
		}

		if err == nil {
			log.Debugf("FsType has been set to %s", fsType)
			err = util.Mount(dev, STATE, fsType, "")
		}
	} else {
		return mountStateTmpfs(cfg)
	}

	return err
}
コード例 #3
0
ファイル: bootstrap.go プロジェクト: slashk/os
func autoformat(cfg *config.Config) error {
	if len(cfg.State.Autoformat) == 0 || util.ResolveDevice(cfg.State.Dev) != "" {
		return nil
	}
	AUTOFORMAT := "AUTOFORMAT=" + strings.Join(cfg.State.Autoformat, " ")
	FORMATZERO := "FORMATZERO=" + fmt.Sprint(cfg.State.FormatZero)
	cfg.Autoformat["autoformat"].Environment = project.NewMaporEqualSlice([]string{AUTOFORMAT, FORMATZERO})
	log.Info("Running Autoformat services")
	err := docker.RunServices("autoformat", cfg, cfg.Autoformat)
	return err
}
コード例 #4
0
ファイル: init.go プロジェクト: clhudson2/os
func mountState(cfg *config.CloudConfig) error {
	var err error

	if cfg.Rancher.State.Dev == "" {
		return nil
	}

	dev := util.ResolveDevice(cfg.Rancher.State.Dev)
	if dev == "" {
		return fmt.Errorf("Could not resolve device %q", cfg.Rancher.State.Dev)
	}
	fsType := cfg.Rancher.State.FsType
	if fsType == "auto" {
		fsType, err = util.GetFsType(dev)
	}

	if err != nil {
		return err
	}

	log.Debugf("FsType has been set to %s", fsType)
	log.Infof("Mounting state device %s to %s", dev, STATE)
	return util.Mount(dev, STATE, fsType, "")
}
コード例 #5
0
ファイル: bootstrap.go プロジェクト: Hellslicer/os
func autoformat(cfg *config.Config) error {
	if len(cfg.State.Autoformat) == 0 || util.ResolveDevice(cfg.State.Dev) != "" {
		return nil
	}

	var format string

outer:
	for _, dev := range cfg.State.Autoformat {
		log.Infof("Checking %s to auto-format", dev)
		if _, err := os.Stat(dev); os.IsNotExist(err) {
			continue
		}

		f, err := os.Open(dev)
		if err != nil {
			return err
		}
		defer f.Close()

		buffer := make([]byte, 1048576, 1048576)
		c, err := f.Read(buffer)
		if err != nil {
			return err
		}

		if c != 1048576 {
			log.Infof("%s not right size", dev)
			continue
		}

		boot2docker := false

		if strings.HasPrefix(string(buffer[:len(boot2dockerMagic)]), boot2dockerMagic) {
			boot2docker = true
		}

		if boot2docker == false {
			for _, b := range buffer {
				if b != 0 {
					log.Infof("%s not empty", dev)
					continue outer
				}
			}
		}

		format = dev
		break
	}

	if format != "" {
		log.Infof("Auto formatting : %s", format)

		// copy
		udev := *cfg.BootstrapContainers["udev"]
		udev.Links = project.NewMaporColonSlice(append(udev.Links.Slice(), "autoformat"))
		udev.LogDriver = "json-file"

		err := docker.RunServices("autoformat", cfg, map[string]*project.ServiceConfig{
			"autoformat": {
				Net:        "none",
				Privileged: true,
				Image:      "rancher/os-autoformat:" + config.VERSION,
				Command:    project.NewCommand(format),
				Labels: project.NewSliceorMap(map[string]string{
					config.DETACH: "false",
					config.SCOPE:  config.SYSTEM,
				}),
				LogDriver: "json-file",
				Environment: project.NewMaporEqualSlice([]string{
					"MAGIC=" + boot2dockerMagic,
				}),
			},
			"udev": &udev,
		})

		return err
	}

	return nil
}
コード例 #6
0
ファイル: dev.go プロジェクト: rowhit/os
func devAction(c *cli.Context) {
	fmt.Println(util.ResolveDevice(c.Args()[0]))
}