mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
1
This commit is contained in:
parent
206d7926b7
commit
4869cd5f39
@ -67,7 +67,7 @@ func Start[T any](ctx context.Context, disc *conf.Discovery, prometheusConfig *c
|
|||||||
)
|
)
|
||||||
if autoSetPorts {
|
if autoSetPorts {
|
||||||
rpcListenAddr = net.JoinHostPort(listenIP, "0")
|
rpcListenAddr = net.JoinHostPort(listenIP, "0")
|
||||||
prometheusListenAddr = net.JoinHostPort("", "0")
|
prometheusListenAddr = net.JoinHostPort(listenIP, "0")
|
||||||
} else {
|
} else {
|
||||||
rpcPort, err := datautil.GetElemByIndex(rpcPorts, index)
|
rpcPort, err := datautil.GetElemByIndex(rpcPorts, index)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -78,7 +78,7 @@ func Start[T any](ctx context.Context, disc *conf.Discovery, prometheusConfig *c
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
rpcListenAddr = net.JoinHostPort(listenIP, strconv.Itoa(rpcPort))
|
rpcListenAddr = net.JoinHostPort(listenIP, strconv.Itoa(rpcPort))
|
||||||
prometheusListenAddr = net.JoinHostPort("", strconv.Itoa(prometheusPort))
|
prometheusListenAddr = net.JoinHostPort(listenIP, strconv.Itoa(prometheusPort))
|
||||||
}
|
}
|
||||||
|
|
||||||
log.CInfo(ctx, "RPC server is initializing", "rpcRegisterName", rpcRegisterName, "rpcAddr", rpcListenAddr, "prometheusAddr", prometheusListenAddr)
|
log.CInfo(ctx, "RPC server is initializing", "rpcRegisterName", rpcRegisterName, "rpcAddr", rpcListenAddr, "prometheusAddr", prometheusListenAddr)
|
||||||
@ -96,11 +96,20 @@ func Start[T any](ctx context.Context, disc *conf.Discovery, prometheusConfig *c
|
|||||||
grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, "round_robin")),
|
grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, "round_robin")),
|
||||||
)
|
)
|
||||||
|
|
||||||
sigs := make(chan os.Signal, 1)
|
|
||||||
signal.Notify(sigs, syscall.SIGTERM)
|
|
||||||
|
|
||||||
ctx, cancel := context.WithCancelCause(ctx)
|
ctx, cancel := context.WithCancelCause(ctx)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
sigs := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(sigs, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL)
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
|
case val := <-sigs:
|
||||||
|
log.ZDebug(ctx, "recv signal", "signal", val.String())
|
||||||
|
cancel(fmt.Errorf("signal %s", val.String()))
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
if prometheusListenAddr != "" {
|
if prometheusListenAddr != "" {
|
||||||
options = append(
|
options = append(
|
||||||
options,
|
options,
|
||||||
@ -176,13 +185,7 @@ func Start[T any](ctx context.Context, disc *conf.Discovery, prometheusConfig *c
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
<-ctx.Done()
|
||||||
select {
|
|
||||||
case val := <-sigs:
|
|
||||||
log.ZDebug(ctx, "recv exit", "signal", val.String())
|
|
||||||
cancel(fmt.Errorf("signal %s", val.String()))
|
|
||||||
case <-ctx.Done():
|
|
||||||
}
|
|
||||||
if rpcGracefulStop != nil {
|
if rpcGracefulStop != nil {
|
||||||
timeout := time.NewTimer(time.Second * 15)
|
timeout := time.NewTimer(time.Second * 15)
|
||||||
defer timeout.Stop()
|
defer timeout.Stop()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user