示例#1
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
}
示例#2
0
func runBootstrapContainers(cfg *config.Config) error {
	return docker.RunServices("bootstrap", cfg, cfg.BootstrapContainers)
}
示例#3
0
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
}
示例#4
0
文件: bootstrap.go 项目: slashk/os
func runBootstrapContainers(cfg *config.Config) error {
	log.Info("Running Bootstrap services")
	return docker.RunServices("bootstrap", cfg, cfg.BootstrapContainers)
}
示例#5
0
文件: sysinit.go 项目: jgatkinsn/os
func runContainers(cfg *config.Config) error {
	return docker.RunServices("system-init", cfg, cfg.SystemContainers)
}