forked from p93542168/wheat-cache
feat(uitl): grace exit
This commit is contained in:
parent
3adeac539b
commit
40374333fa
|
@ -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)
|
||||
}
|
||||
}()
|
||||
}
|
Loading…
Reference in New Issue