コード例 #1
0
ファイル: helpers.go プロジェクト: ZhuZhengyi/eris-db
func CreateTempWorkDir(privValidator *types.PrivValidator, genesis *stypes.GenesisDoc, folderName string) (string, error) {

	workDir := path.Join(os.TempDir(), folderName)
	os.RemoveAll(workDir)
	errED := EnsureDir(workDir)

	if errED != nil {
		return "", errED
	}

	cfgName := path.Join(workDir, "config.toml")
	scName := path.Join(workDir, "server_conf.toml")
	pvName := path.Join(workDir, "priv_validator.json")
	genesisName := path.Join(workDir, "genesis.json")

	// Write config.
	errCFG := files.WriteFileRW(cfgName, []byte(TendermintConfigDefault))
	if errCFG != nil {
		return "", errCFG
	}
	fmt.Printf("File written: %s\n.", cfgName)

	// Write validator.
	errPV := writeJSON(pvName, privValidator)
	if errPV != nil {
		return "", errPV
	}
	fmt.Printf("File written: %s\n.", pvName)

	// Write genesis
	errG := writeJSON(genesisName, genesis)
	if errG != nil {
		return "", errG
	}
	fmt.Printf("File written: %s\n.", genesisName)

	// Write server config.
	errWC := server.WriteServerConfig(scName, server.DefaultServerConfig())
	if errWC != nil {
		return "", errWC
	}
	fmt.Printf("File written: %s\n.", scName)
	return workDir, nil
}
コード例 #2
0
ファイル: server_manager.go プロジェクト: ZhuZhengyi/eris-db
// Creates a temp folder for the tendermint/erisdb node to run in.
// Folder name is port based, so port=1337 meens folder="testnode1337"
// Old folders are cleared out. before creating them, and the server will
// clean out all of this servers workdir (defaults to ~/.edbservers) when
// starting and when stopping.
func (this *ServerManager) createWorkDir(data *RequestData, config *server.ServerConfig, folderName string) (string, error) {

	workDir := path.Join(this.baseDir, folderName)
	os.RemoveAll(workDir)
	errED := EnsureDir(workDir)
	if errED != nil {
		return "", errED
	}

	cfgName := path.Join(workDir, "config.toml")
	scName := path.Join(workDir, "server_conf.toml")
	pvName := path.Join(workDir, "priv_validator.json")
	genesisName := path.Join(workDir, "genesis.json")

	// Write config.
	errCFG := files.WriteFileRW(cfgName, []byte(TendermintConfigDefault))
	if errCFG != nil {
		return "", errCFG
	}
	log.Info("File written.", "name", cfgName)

	// Write validator.
	errPV := writeJSON(pvName, data.PrivValidator)
	if errPV != nil {
		return "", errPV
	}
	log.Info("File written.", "name", pvName)

	// Write genesis
	errG := writeJSON(genesisName, data.Genesis)
	if errG != nil {
		return "", errG
	}
	log.Info("File written.", "name", genesisName)

	// Write server config.
	errWC := server.WriteServerConfig(scName, config)
	if errWC != nil {
		return "", errWC
	}
	log.Info("File written.", "name", scName)
	return workDir, nil
}