示例#1
0
文件: raftX.go 项目: izouxv/raftX
func main() {
	go func() {
		//http://localhost:6060/debug/pprof/
		log.Println(http.ListenAndServe("localhost:6060", nil))
	}()

	log.SetFlags(0)
	flag.Parse()
	if verbose {
		log.Print("Verbose logging enabled.")
	}
	if trace {
		raft.SetLogLevel(raft.Trace)
		log.Print("Raft trace debugging enabled.")
	} else if debug {
		raft.SetLogLevel(raft.Debug)
		log.Print("Raft debugging enabled.")
	}

	rand.Seed(time.Now().UnixNano())

	// Setup commands.
	raft.RegisterCommand(&command.SetCommand{})
	raft.RegisterCommand(&command.RemoveTmpDataCommand{})

	// Set the data directory.
	if flag.NArg() == 0 {
		flag.Usage()
		log.Fatal("Data path argument required")
	}
	path := flag.Arg(0)
	if err := os.MkdirAll(path, 0744); err != nil {
		log.Fatalf("Unable to create path: %v", err)
	}

	//	log.Fatalf("join: %v", join)
	//	log.Fatalf(" path: %v", path)

	log.SetFlags(log.LstdFlags)
	s := server.New(path, host, port)

	if true {
		runtime.GOMAXPROCS(runtime.NumCPU())
	}
	addr := fmt.Sprintf("%s:%d", host, tcpSerPort)

	//log.Fatal(s.ListenAndServe(join, addr))
	s.ListenAndServe(join, addr)
	select {}
}
示例#2
0
func startSer() {

	// Setup commands.
	raft.RegisterCommand(&command.SetCommand{})
	raft.RegisterCommand(&command.RemoveTmpDataCommand{})

	path := kPath
	if err := os.MkdirAll(path, 0744); err != nil {
		log.Fatalf("Unable to create path: %v", err)
	}

	log.SetFlags(log.LstdFlags)
	s := server.New(path, host, port)

	addr := fmt.Sprintf("%s:%d", host, tcpSerPort)

	s.ListenAndServe(join, addr)
}