// createCluster creates a cluster, numNodes in size, using path for storage // for all nodes. The first node in the returned slice of nodes will be the // cluster leader. func createCluster(t *testing.T, numNodes int, host string, basePort int, path string) []*testServer { var nodes []*testServer // Create first differently, since it is the leader. nodePath := filepath.Join(path, "0") mustMkDirAll(nodePath) s := server.NewServer(nodePath, "db.sqlite", 100000, host, basePort) go func() { t.Fatal(s.ListenAndServe("")) }() nodes = append(nodes, &testServer{host: host, port: basePort, server: s}) time.Sleep(spinUpDelay) // Create remaining nodes in cluster. for i := 1; i < numNodes; i++ { port := basePort + i nodePath := filepath.Join(path, strconv.Itoa(i)) mustMkDirAll(nodePath) s := server.NewServer(nodePath, "db.sqlite", 100000, host, port) go func() { t.Fatal(s.ListenAndServe(host + ":" + strconv.Itoa(basePort))) }() nodes = append(nodes, &testServer{host: host, port: port, server: s}) time.Sleep(spinUpDelay) } return nodes }
func main() { flag.Parse() // Set up profiling, if requested. if cpuprofile != "" { log.Info("Profiling enabled") f, err := os.Create(cpuprofile) if err != nil { log.Errorf("Unable to create path: %s", err.Error()) } defer closeFile(f) err = pprof.StartCPUProfile(f) if err != nil { log.Errorf("Unable to start CPU Profile: %s", err.Error()) } defer pprof.StopCPUProfile() } // Set logging log.SetLevel(logLevel) if logFile != "stdout" { f := createFile(logFile) defer closeFile(f) log.Infof("Redirecting logging to %s", logFile) log.SetOutput(f) } // Set the data directory. if flag.NArg() == 0 { flag.Usage() println("Data path argument required") log.Error("No data path supplied -- aborting") os.Exit(1) } dataPath := flag.Arg(0) createDir(dataPath) s := server.NewServer(dataPath, dbfile, snapAfter, host, port) go func() { log.Error(s.ListenAndServe(join).Error()) }() if !disableReporting { reportLaunch() } terminate := make(chan os.Signal, 1) signal.Notify(terminate, os.Interrupt) <-terminate log.Info("rqlite server stopped") }
func main() { flag.Parse() // Set up profiling, if requested. if cpuprofile != "" { log.Info("Profiling enabled") f, err := os.Create(cpuprofile) if err != nil { log.Error("Unable to create path: %w", err) } defer f.Close() pprof.StartCPUProfile(f) defer pprof.StopCPUProfile() } setupLogging(logLevel, logFile) // Set the data directory. if flag.NArg() == 0 { flag.Usage() println("Data path argument required") log.Error("No data path supplied -- aborting") os.Exit(1) } path := flag.Arg(0) if err := os.MkdirAll(path, 0744); err != nil { log.Error("Unable to create path: %v", err) } s := server.NewServer(path, dbfile, snapAfter, host, port) go func() { log.Error(s.ListenAndServe(join)) }() terminate := make(chan os.Signal, 1) signal.Notify(terminate, os.Interrupt) <-terminate log.Info("rqlite server stopped") }