Beispiel #1
0
func stop() (err error) {
	clientConn, err := peer.NewPeerClientConnection()
	if err != nil {
		pidFile := stopPidFile + "/peer.pid"
		//fmt.Printf("Stopping local peer using process pid from %s \n", pidFile)
		logger.Infof("Error trying to connect to local peer: %s", err)
		logger.Infof("Stopping local peer using process pid from %s", pidFile)
		pid, ferr := readPid(pidFile)
		if ferr != nil {
			err = fmt.Errorf("Error trying to read pid from %s: %s", pidFile, ferr)
			return
		}
		killerr := syscall.Kill(pid, syscall.SIGTERM)
		if killerr != nil {
			err = fmt.Errorf("Error trying to kill -9 pid %d: %s", pid, killerr)
			return
		}
		return nil
	}
	logger.Info("Stopping peer using grpc")
	serverClient := pb.NewAdminClient(clientConn)

	status, err := serverClient.StopServer(context.Background(), &empty.Empty{})
	db.Stop()
	if err != nil {
		fmt.Println(&pb.ServerStatus{Status: pb.ServerStatus_STOPPED})
		return nil
	}

	err = fmt.Errorf("Connection remain opened, peer process doesn't exit")
	fmt.Println(status)
	return err
}
Beispiel #2
0
func main() {
	flagSetName := os.Args[0]
	flagSet := flag.NewFlagSet(flagSetName, flag.ExitOnError)
	dbDirPtr := flagSet.String("dbDir", "", "path to db dump")
	flagSet.Parse(os.Args[1:])

	dbDir := *dbDirPtr

	if dbDir == "" {
		fmt.Fprintf(os.Stderr, "Usage of %s:\n", flagSetName)
		flagSet.PrintDefaults()
		os.Exit(3)
	}
	viper.Set("peer.fileSystemPath", dbDir)
	fmt.Printf("dbDir = [%s]\n", dbDir)

	// check that dbDir exists
	if _, err := os.Stat(dbDir); os.IsNotExist(err) {
		fmt.Fprintln(os.Stderr, "dbDir does not exist")
		os.Exit(4)
	}

	if _, err := os.Stat(dbDir + "/db"); os.IsNotExist(err) {
		fmt.Fprintln(os.Stderr, "dbDir does not contain a sub-dir named 'db'")
		os.Exit(5)
	}

	db.Start()
	openchainDB := db.GetDBHandle()
	defer db.Stop()
	fmt.Println()
	scan(openchainDB, "blockchainCF", openchainDB.BlockchainCF, blockDetailPrinter)
	fmt.Println()
	scan(openchainDB, "persistCF", openchainDB.PersistCF, nil)
	fmt.Println()
	printLiveFilesMetaData(openchainDB)
	fmt.Println()
	printProperties(openchainDB)
	fmt.Println()
}