code: func newServer(ctx *cli.Context) (server *rpc.Server, cleanup func(), err error) {
  	log.PrintOrigins(true)
  	log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(ctx.Int("verbosity")), log.StreamHandler(os.Stdout, log.TerminalFormat(false))))
  
  	cleanup = func() {}
  	var globalStore mock.GlobalStorer
  	dir := ctx.String("dir")
  	if dir != "" {
  		dbStore, err := db.NewGlobalStore(dir)
  		if err != nil {
  			return nil, nil, err
  		}
  		cleanup = func() {
  			if err := dbStore.Close(); err != nil {
  				log.Error("global store: close", "err", err)
  			}
  		}
  		globalStore = dbStore
  		log.Info("database global store", "dir", dir)
  	} else {
  		globalStore = mem.NewGlobalStore()
  		log.Info("in-memory global store")
  	}
  
  	server = rpc.NewServer()
  	if err := server.RegisterName("mockStore", globalStore); err != nil {
  		cleanup()
  		return nil, nil, err
  	}
  
  	shutdown, err := serveChunkExplorer(ctx, globalStore)
  	if err != nil {
  		cleanup()
  		return nil, nil, err
  	}
  	if shutdown != nil {
  		cleanup = func() {
  			shutdown()
  
  			if c, ok := globalStore.(io.Closer); ok {
  				if err := c.Close(); err != nil {
  					log.Error("global store: close", "err", err)
  				}
  			}
  		}
  	}
  
  	return server, cleanup, nil
  }
docs: // newServer creates a global store and starts a chunk explorer server if configured.
  // Returned cleanup function should be called only if err is nil.