diff --git a/pkg/util/server/os.go b/pkg/util/server/os.go new file mode 100644 index 0000000..20f368c --- /dev/null +++ b/pkg/util/server/os.go @@ -0,0 +1,29 @@ +package server + +import ( + "os" + "os/signal" + "syscall" + + "gitee.com/timedb/wheatCache/pkg/logx" + "google.golang.org/grpc" +) + +func ElegantExitServer(s *grpc.Server) { + c := make(chan os.Signal) + signal.Notify(c, syscall.SIGHUP, syscall.SIGINT) + go func() { + select { + case <-c: + s.Stop() + + msg := ` + |-------Wheat tools---------| + | see you next time | + |thank you for your efforts | + |---------------------------| + ` + logx.Infoln(msg) + } + }() +}