|
|
@ -17,6 +17,8 @@ package startrpc
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/openimsdk/tools/discovery"
|
|
|
|
|
|
|
|
"github.com/openimsdk/tools/system/program"
|
|
|
|
"net"
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
@ -29,10 +31,9 @@ import (
|
|
|
|
"github.com/openimsdk/tools/log"
|
|
|
|
"github.com/openimsdk/tools/log"
|
|
|
|
|
|
|
|
|
|
|
|
grpcprometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
|
|
|
grpcprometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
|
|
|
"github.com/openimsdk/tools/discoveryregistry"
|
|
|
|
|
|
|
|
"github.com/openimsdk/tools/errs"
|
|
|
|
"github.com/openimsdk/tools/errs"
|
|
|
|
"github.com/openimsdk/tools/mw"
|
|
|
|
"github.com/openimsdk/tools/mw"
|
|
|
|
"github.com/openimsdk/tools/network"
|
|
|
|
"github.com/openimsdk/tools/utils/network"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc"
|
|
|
@ -42,11 +43,10 @@ import (
|
|
|
|
config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
|
|
|
config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
|
|
|
kdisc "github.com/openimsdk/open-im-server/v3/pkg/common/discoveryregister"
|
|
|
|
kdisc "github.com/openimsdk/open-im-server/v3/pkg/common/discoveryregister"
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/prommetrics"
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/prommetrics"
|
|
|
|
util "github.com/openimsdk/open-im-server/v3/pkg/util/genutil"
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// Start rpc server.
|
|
|
|
// Start rpc server.
|
|
|
|
func Start(ctx context.Context, rpcPort int, rpcRegisterName string, prometheusPort int, config *config2.GlobalConfig, rpcFn func(ctx context.Context, config *config.GlobalConfig, client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error, options ...grpc.ServerOption) error {
|
|
|
|
func Start(ctx context.Context, rpcPort int, rpcRegisterName string, prometheusPort int, config *config2.GlobalConfig, rpcFn func(ctx context.Context, config *config.GlobalConfig, client discovery.SvcDiscoveryRegistry, server *grpc.Server) error, options ...grpc.ServerOption) error {
|
|
|
|
log.CInfo(ctx, "RPC server is initializing", "rpcRegisterName", rpcRegisterName, "rpcPort", rpcPort,
|
|
|
|
log.CInfo(ctx, "RPC server is initializing", "rpcRegisterName", rpcRegisterName, "rpcPort", rpcPort,
|
|
|
|
"prometheusPort", prometheusPort)
|
|
|
|
"prometheusPort", prometheusPort)
|
|
|
|
rpcTcpAddr := net.JoinHostPort(network.GetListenIP(config.Rpc.ListenIP), strconv.Itoa(rpcPort))
|
|
|
|
rpcTcpAddr := net.JoinHostPort(network.GetListenIP(config.Rpc.ListenIP), strconv.Itoa(rpcPort))
|
|
|
@ -133,7 +133,7 @@ func Start(ctx context.Context, rpcPort int, rpcRegisterName string, prometheusP
|
|
|
|
signal.Notify(sigs, syscall.SIGTERM)
|
|
|
|
signal.Notify(sigs, syscall.SIGTERM)
|
|
|
|
select {
|
|
|
|
select {
|
|
|
|
case <-sigs:
|
|
|
|
case <-sigs:
|
|
|
|
util.SIGTERMExit()
|
|
|
|
program.SIGTERMExit()
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
defer cancel()
|
|
|
|
if err := gracefulStopWithCtx(ctx, srv.GracefulStop); err != nil {
|
|
|
|
if err := gracefulStopWithCtx(ctx, srv.GracefulStop); err != nil {
|
|
|
|