示例#1
0
func runBootstrap(args *docopt.Args) {
	log.SetFlags(log.Lmicroseconds)
	logf := textLogger
	if args.Bool["--json"] {
		logf = jsonLogger
	}

	var err error
	manifest, err = readBootstrapManifest(args.String["<manifest>"])
	if err != nil {
		log.Fatalln("Error reading manifest:", err)
	}

	ch := make(chan *bootstrap.StepInfo)
	done := make(chan struct{})
	go func() {
		for si := range ch {
			logf(si)
		}
		close(done)
	}()

	minHosts, _ := strconv.Atoi(args.String["--min-hosts"])
	err = bootstrap.Run(manifest, ch, minHosts)
	<-done
	if err != nil {
		os.Exit(1)
	}
}
示例#2
0
func main() {
	logJSON := flag.Bool("json", false, "format log output as json")
	minHosts := flag.Int("min-hosts", 1, "minimum number of hosts required to be online")
	flag.Parse()

	log.SetFlags(log.Lmicroseconds)
	logf := textLogger
	if *logJSON {
		logf = jsonLogger
	}

	var err error
	manifest, err = readManifest()
	if err != nil {
		log.Fatalln("Error reading manifest:", err)
	}

	ch := make(chan *bootstrap.StepInfo)
	done := make(chan struct{})
	go func() {
		for si := range ch {
			logf(si)
		}
		close(done)
	}()

	err = bootstrap.Run(manifest, ch, *minHosts)
	<-done
	if err != nil {
		os.Exit(1)
	}
}
示例#3
0
文件: bootstrap.go 项目: rikur/flynn
func runBootstrap(args *docopt.Args) {
	log.SetFlags(log.Lmicroseconds)
	logf := textLogger
	if args.Bool["--json"] {
		logf = jsonLogger
	}

	manifestFile := args.String["<manifest>"]
	if manifestFile == "" {
		manifestFile = "/etc/flynn/bootstrap-manifest.json"
	}

	var err error
	manifest, err = readBootstrapManifest(manifestFile)
	if err != nil {
		log.Fatalln("Error reading manifest:", err)
	}

	var minHosts int
	if n := args.String["--min-hosts"]; n != "" {
		if minHosts, err = strconv.Atoi(n); err != nil || minHosts < 1 {
			log.Fatalln("invalid --min-hosts value")
		}
	}

	timeout, err := strconv.Atoi(args.String["--timeout"])
	if err != nil {
		log.Fatalln("invalid --timeout value")
	}

	var ips []string
	if ipList := args.String["--peer-ips"]; ipList != "" {
		ips = strings.Split(ipList, ",")
		if minHosts == 0 {
			minHosts = len(ips)
		}
	}

	if minHosts == 0 {
		minHosts = 1
	}

	ch := make(chan *bootstrap.StepInfo)
	done := make(chan struct{})
	go func() {
		for si := range ch {
			logf(si)
		}
		close(done)
	}()

	err = bootstrap.Run(manifest, ch, args.String["--discovery"], ips, minHosts, timeout)
	<-done
	if err != nil {
		os.Exit(1)
	}
}
示例#4
0
func runBootstrap(args *docopt.Args) error {
	log.SetFlags(log.Lmicroseconds)
	logf := textLogger
	if args.Bool["--json"] {
		logf = jsonLogger
	}
	var cfg bootstrap.Config

	manifestFile := args.String["<manifest>"]
	if manifestFile == "" {
		manifestFile = "/etc/flynn/bootstrap-manifest.json"
	}

	var steps []string
	if s := args.String["--steps"]; s != "" {
		steps = strings.Split(s, ",")
	}

	var err error
	manifest, err = readBootstrapManifest(manifestFile)
	if err != nil {
		return fmt.Errorf("Error reading manifest: %s", err)
	}

	if n := args.String["--min-hosts"]; n != "" {
		if cfg.MinHosts, err = strconv.Atoi(n); err != nil || cfg.MinHosts < 1 {
			return fmt.Errorf("invalid --min-hosts value")
		}
	}

	cfg.Timeout, err = strconv.Atoi(args.String["--timeout"])
	if err != nil {
		return fmt.Errorf("invalid --timeout value")
	}

	if ipList := args.String["--peer-ips"]; ipList != "" {
		cfg.IPs = strings.Split(ipList, ",")
		if cfg.MinHosts == 0 {
			cfg.MinHosts = len(cfg.IPs)
		}
	}

	if cfg.MinHosts == 0 {
		cfg.MinHosts = 1
	}

	cfg.Singleton = cfg.MinHosts == 1
	if s := os.Getenv("SINGLETON"); s != "" {
		cfg.Singleton = s == "true"
	}

	ch := make(chan *bootstrap.StepInfo)
	done := make(chan struct{})
	var last error
	go func() {
		for si := range ch {
			logf(si)
			last = si.Err
		}
		close(done)
	}()

	cfg.ClusterURL = args.String["--discovery"]
	if bf := args.String["--from-backup"]; bf != "" {
		err = runBootstrapBackup(manifest, bf, ch, cfg)
	} else {
		err = bootstrap.Run(manifest, ch, cfg, steps)
	}

	<-done
	if err != nil && last != nil && err.Error() == last.Error() {
		return ErrAlreadyLogged{err}
	}
	return err
}