mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-03 02:42:19 +08:00
fix: add signal Exit code
This commit is contained in:
parent
eec0a5b69a
commit
2711029a98
@ -119,7 +119,7 @@ func run(port int, proPort int) error {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
select {
|
select {
|
||||||
case <-sigs:
|
case <-sigs:
|
||||||
util.SIGUSR1Exit()
|
util.SIGTERMExit()
|
||||||
err := server.Shutdown(ctx)
|
err := server.Shutdown(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errs.Wrap(err, "shutdown err")
|
return errs.Wrap(err, "shutdown err")
|
||||||
|
|||||||
@ -46,9 +46,7 @@ func RunWsAndServer(rpcPort, wsPort, prometheusPort int) error {
|
|||||||
netDone := make(chan error)
|
netDone := make(chan error)
|
||||||
go func() {
|
go func() {
|
||||||
err = hubServer.Start()
|
err = hubServer.Start()
|
||||||
//if err != nil {
|
|
||||||
netDone <- err
|
netDone <- err
|
||||||
//}
|
|
||||||
}()
|
}()
|
||||||
return hubServer.LongConnServer.Run(netDone)
|
return hubServer.LongConnServer.Run(netDone)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
util "github.com/openimsdk/open-im-server/v3/pkg/util/genutil"
|
||||||
|
|
||||||
"github.com/OpenIMSDK/tools/errs"
|
"github.com/OpenIMSDK/tools/errs"
|
||||||
"github.com/OpenIMSDK/tools/log"
|
"github.com/OpenIMSDK/tools/log"
|
||||||
@ -142,6 +143,7 @@ func (m *MsgTransfer) Start(prometheusPort int) error {
|
|||||||
signal.Notify(sigs, syscall.SIGTERM)
|
signal.Notify(sigs, syscall.SIGTERM)
|
||||||
select {
|
select {
|
||||||
case <-sigs:
|
case <-sigs:
|
||||||
|
util.SIGTERMExit()
|
||||||
// graceful close kafka client.
|
// graceful close kafka client.
|
||||||
m.cancel()
|
m.cancel()
|
||||||
m.historyCH.historyConsumerGroup.Close()
|
m.historyCH.historyConsumerGroup.Close()
|
||||||
|
|||||||
@ -29,6 +29,8 @@ import (
|
|||||||
|
|
||||||
"github.com/OpenIMSDK/tools/errs"
|
"github.com/OpenIMSDK/tools/errs"
|
||||||
|
|
||||||
|
util "github.com/openimsdk/open-im-server/v3/pkg/util/genutil"
|
||||||
|
|
||||||
"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"
|
||||||
|
|
||||||
@ -138,6 +140,7 @@ func Start(
|
|||||||
signal.Notify(sigs, syscall.SIGTERM)
|
signal.Notify(sigs, syscall.SIGTERM)
|
||||||
select {
|
select {
|
||||||
case <-sigs:
|
case <-sigs:
|
||||||
|
util.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 {
|
||||||
@ -149,12 +152,11 @@ func Start(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errs.Wrap(err, "shutdown err")
|
return errs.Wrap(err, "shutdown err")
|
||||||
}
|
}
|
||||||
//return errs.Wrap(errors.New("SIGTERM EXIT"))
|
return nil
|
||||||
case <-netDone:
|
case <-netDone:
|
||||||
close(netDone)
|
close(netDone)
|
||||||
return netErr
|
return netErr
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func gracefulStopWithCtx(ctx context.Context, f func()) error {
|
func gracefulStopWithCtx(ctx context.Context, f func()) error {
|
||||||
|
|||||||
@ -51,7 +51,7 @@ func ExitWithError(err error) {
|
|||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SIGUSR1Exit() {
|
func SIGTERMExit() {
|
||||||
progName := filepath.Base(os.Args[0])
|
progName := filepath.Base(os.Args[0])
|
||||||
fmt.Printf("\n\n%s receive process terminal SIGTERM exit 0\n\n", progName)
|
fmt.Printf("%s receive process terminal SIGTERM exit 0", progName)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,6 +36,4 @@ openim::util::stop_services_by_name_signal "${OPENIM_OUTPUT_HOSTBIN}"
|
|||||||
|
|
||||||
echo "++ Check if the services have been stopped"
|
echo "++ Check if the services have been stopped"
|
||||||
|
|
||||||
source "${OPENIM_ROOT}/scripts/check-all-by-signal.sh"
|
|
||||||
|
|
||||||
openim::log::success "✨ All processes to be killed"
|
openim::log::success "✨ All processes to be killed"
|
||||||
Loading…
x
Reference in New Issue
Block a user