Example #1
0
func main() {
	log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
	log.Printf("Current PID: %d", os.Getpid())
	flag.Parse()
	runtime.SetBlockProfileRate(1)

	ctx, cancel := context.WithCancel(context.Background())

	if *taskName == "" {
		hostname, err := os.Hostname()
		if err != nil {
			log.Fatalf("Unable to get hostname, set --name: %s", err)
		}
		*taskName = hostname
	}

	cs := store_config.NewLocalConfigStore(filepath.Join(*storePath, "config.txt"), *taskName)
	if err := cs.Start(ctx); err != nil {
		log.Fatalf("Error starting config store: %s", err)
	}
	store_config.Set(cs)

	log.Printf("Opening store")
	ds := datastore.Open(ctx, *storePath)
	log.Printf("Finished opening store, serving")

	go rpc_server.Serve(ds)
	go http_server.Serve(ds)
	cs.UpdateThisState(ctx, oproto.ClusterMember_RUN)

	shutdown := make(chan struct{})
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	go func() {
		for sig := range c {
			log.Printf("Caught signal %s, shutting down", sig)
			close(shutdown)
		}
	}()
	<-shutdown

	// Drain server
	cs.UpdateThisState(ctx, oproto.ClusterMember_DRAIN)
	// TODO(drain)

	// Shut down server
	cs.UpdateThisState(ctx, oproto.ClusterMember_SHUTDOWN)

	cs.Stop()
	cancel()
}
Example #2
0
func (s *MySuite) SetUpSuite(c *C) {
	s.dataDir = c.MkDir()
	cs := store_config.NewLocalConfigStore(filepath.Join(s.dataDir, "config.txt"), "test")
	cs.Start(context.Background())
	store_config.Set(cs)
}