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{}) 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 }
// GetAdminClient returns a new admin client connection for this peer func GetAdminClient() (pb.AdminClient, error) { clientConn, err := peer.NewPeerClientConnection() if err != nil { err = errors.ErrorWithCallstack(errors.Peer, errors.PeerConnectionError, err.Error()) return nil, err } adminClient := pb.NewAdminClient(clientConn) return adminClient, nil }