feat(uitl): grace exit

This commit is contained in:
bandl 2021-10-16 22:51:28 +08:00
parent 3adeac539b
commit 40374333fa
1 changed files with 29 additions and 0 deletions

29
pkg/util/server/os.go Normal file
View File

@ -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)
}
}()
}