コード例 #1
0
ファイル: main.go プロジェクト: hanslovsky/dvid
// DoServe opens a datastore then creates both web and rpc servers for the datastore
func DoServe(cmd dvid.Command) error {
	// Capture ctrl+c and other interrupts.  Then handle graceful shutdown.
	stopSig := make(chan os.Signal)
	go func() {
		for sig := range stopSig {
			log.Printf("Stop signal captured: %q.  Shutting down...\n", sig)
			if *memprofile != "" {
				log.Printf("Storing memory profiling to %s...\n", *memprofile)
				f, err := os.Create(*memprofile)
				if err != nil {
					log.Fatal(err)
				}
				pprof.WriteHeapProfile(f)
				f.Close()
			}
			if *cpuprofile != "" {
				log.Printf("Stopping CPU profiling to %s...\n", *cpuprofile)
				pprof.StopCPUProfile()
			}
			server.Shutdown()
			time.Sleep(1 * time.Second)
			os.Exit(0)
		}
	}()
	signal.Notify(stopSig, os.Interrupt, os.Kill, syscall.SIGTERM)

	// Check if there is a configuration file, and if so, set logger.
	logConfig, err := server.LoadConfig(*configfile)
	if err != nil {
		return fmt.Errorf("Error loading configuration file %q: %v\n", *configfile, err)
	}
	logConfig.SetLogger()

	// Load datastore metadata and initialize datastore
	dbpath := cmd.Argument(1)
	if dbpath == "" {
		return fmt.Errorf("serve command must be followed by the path to the datastore")
	}
	if err := local.Initialize(dbpath, cmd.Settings()); err != nil {
		return fmt.Errorf("Unable to initialize local storage: %v\n", err)
	}
	if err := datastore.Initialize(); err != nil {
		return fmt.Errorf("Unable to initialize datastore: %v\n", err)
	}

	// add handlers to help us track memory usage - they don't track memory until they're told to
	profiler.AddMemoryProfilingHandlers()

	// Uncomment if you want to start profiling automatically
	// profiler.StartProfiling()

	// listen on port 6060 (pick a port)
	go http.ListenAndServe(":6060", nil)

	// Serve HTTP and RPC
	if err := server.Serve(*httpAddress, *clientDir, *rpcAddress); err != nil {
		return err
	}
	return nil
}
コード例 #2
0
ファイル: test_local.go プロジェクト: hanslovsky/dvid
// CloseReopenStore forces close of the underlying storage engine and then reopening
// the datastore.  Useful for testing metadata persistence.
func CloseReopenStore() {
	mu.Lock()
	defer mu.Unlock()
	dvid.BlockOnActiveCgo()
	if engine == nil {
		log.Fatalf("Attempted to close and reopen non-existant engine!")
	}
	engine.Close()

	var err error
	create := false
	engine, err = local.NewKeyValueStore(dbpath, create, dvid.Config{})
	if err != nil {
		log.Fatalf("Error reopening test db at %s: %v\n", dbpath, err)
	}
	if err = storage.Initialize(engine, "testdb"); err != nil {
		log.Fatalf("CloseReopenStore: bad storage.Initialize(): %v\n", err)
	}
	if err = datastore.Initialize(); err != nil {
		log.Fatalf("CloseReopenStore: can't initialize datastore management: %v\n", err)
	}
}
コード例 #3
0
ファイル: test_local.go プロジェクト: hanslovsky/dvid
func UseStore() {
	mu.Lock()
	defer mu.Unlock()
	if count == 0 {
		dbpath = filepath.Join(os.TempDir(), fmt.Sprintf("dvid-test-%s", uuid.NewV4()))
		var err error
		engine, err = local.CreateBlankStore(dbpath)
		if err != nil {
			log.Fatalf("Can't create a blank test datastore: %v\n", err)
		}
		if err = storage.Initialize(engine, "testdb"); err != nil {
			log.Fatalf("Can't initialize test datastore: %v\n", err)
		}
		if err = datastore.InitMetadata(engine); err != nil {
			log.Fatalf("Can't write blank datastore metadata: %v\n", err)
		}
		if err = datastore.Initialize(); err != nil {
			log.Fatalf("Can't initialize datastore management: %v\n", err)
		}
	}
	count++
}