forked from TrueCloudLab/frostfs-node
[#323] cmd/node: Compose functions for closing components in app
Closing callback can be registered in app through onShutdown method. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
707434efa9
commit
9f41192bff
4 changed files with 29 additions and 4 deletions
|
@ -4,6 +4,8 @@ import (
|
|||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/reflection"
|
||||
)
|
||||
|
@ -17,6 +19,10 @@ func initGRPC(c *cfg) {
|
|||
c.cfgGRPC.server = grpc.NewServer(
|
||||
grpc.MaxSendMsgSize(c.viper.GetInt(cfgMaxMsgSize)),
|
||||
)
|
||||
|
||||
c.onShutdown(func() {
|
||||
stopGRPC("NeoFS Public API", c.cfgGRPC.server, c.log)
|
||||
})
|
||||
}
|
||||
|
||||
func serveGRPC(c *cfg) {
|
||||
|
@ -38,3 +44,13 @@ func serveGRPC(c *cfg) {
|
|||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func stopGRPC(name string, s *grpc.Server, l *logger.Logger) {
|
||||
l = l.With(zap.String("name", name))
|
||||
|
||||
l.Info("stopping gRPC server...")
|
||||
|
||||
s.GracefulStop()
|
||||
|
||||
l.Info("gRPC server stopped successfully")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue