Exemplo n.º 1
0
func main() {
	flag.Parse()

	store.Logging = *verbose

	rc, e := trib.LoadRC(*frc)
	noError(e)

	run := func(i int) {
		if i > len(rc.Backs) {
			noError(fmt.Errorf("back-end index out of range: %d", i))
		}

		backConfig := rc.BackConfig(i, store.NewStorage())

		if *readyAddr != "" {
			backConfig.Ready = ready.Chan(*readyAddr, backConfig.Addr)
		}

		log.Printf("bin storage back-end serving on %s", backConfig.Addr)
		noError(triblab.ServeBack(backConfig))
	}

	args := flag.Args()

	n := 0
	if len(args) == 0 {
		// scan for addresses on this machine
		for i, b := range rc.Backs {
			if local.Check(b) {
				go run(i)
				n++
			}
		}

		if n == 0 {
			log.Fatal("no back-end found for this host")
		}
	} else {
		// scan for indices for the addresses
		for _, a := range args {
			i, e := strconv.Atoi(a)
			noError(e)
			go run(i)
			n++
		}
	}

	if n > 0 {
		select {}
	}
}
Exemplo n.º 2
0
func main() {
	flag.Parse()

	rc, e := trib.LoadRC(*frc)
	noError(e)

	run := func(i int) {
		if i > len(rc.Keepers) {
			noError(fmt.Errorf("keeper index out of range: %d", i))
		}

		keeperConfig := rc.KeeperConfig(i)
		c := make(chan bool)
		keeperConfig.Ready = c
		go func() {
			noError(triblab.ServeKeeper(keeperConfig))
		}()

		b := <-c
		if b {
			log.Printf("bin storage keeper serving on %s",
				keeperConfig.Addr())
			if *readyAddr != "" {
				ready.Notify(*readyAddr, keeperConfig.Addr())
			}
		} else {
			log.Printf("bin storage keeper on %s init failed",
				keeperConfig.Addr())
			if *readyAddr != "" {
				ready.NotifyFail(*readyAddr, keeperConfig.Addr())
			}
		}
	}

	args := flag.Args()
	n := 0
	if len(args) == 0 {
		for i, k := range rc.Keepers {
			if local.Check(k) {
				go run(i)
				n++
			}
		}

		if n == 0 {
			log.Fatal("no keeper found for this host")
		}
	} else {
		for _, a := range args {
			i, e := strconv.Atoi(a)
			noError(e)

			go run(i)
			n++
		}
	}

	if n > 0 {
		select {}
	}
}