Revert "Revert "优化服务退出流程,增加中间件文档""

This reverts commit 64ed43b7ca.
This commit is contained in:
maxbad
2023-05-15 23:17:59 +08:00
parent 64ed43b7ca
commit 06292b603b
30 changed files with 335 additions and 97 deletions

View File

@@ -10,13 +10,11 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/os/gcmd"
"hotgo/internal/crons"
"hotgo/internal/library/addons"
"hotgo/internal/library/casbin"
"hotgo/internal/router"
"hotgo/internal/service"
"hotgo/internal/websocket"
"os"
)
var (
@@ -77,13 +75,20 @@ var (
// https
setSSL(ctx, s)
// 退出信号监听
signalListen(ctx, func(sig os.Signal) {
s.Shutdown()
crons.StopALL()
websocket.Stop()
service.TCPServer().Stop(ctx)
})
serverWg.Add(1)
// 信号监听
signalListen(ctx, signalHandlerForOverall)
go func() {
select {
case <-serverCloseSignal:
websocket.Stop()
service.TCPServer().Stop(ctx)
s.Shutdown() // 主服务建议放在最后一个关闭
g.Log().Debug(ctx, "http successfully closed ..")
serverWg.Done()
}
}()
// Just run the server.
s.Run()