45 Star 300 Fork 76

GVPYoMo/yomo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
zipper_notwindows.go 1.07 KB
一键复制 编辑 原始数据 按行查看 历史
//go:build !windows
// +build !windows
package yomo
import (
"os"
"os/signal"
"runtime"
"syscall"
"github.com/yomorun/yomo/core"
"github.com/yomorun/yomo/core/ylog"
)
// initialize when zipper running as server. support inspection:
// - `kill -SIGUSR1 <pid>` inspect state()
// - `kill -SIGTERM <pid>` graceful shutdown
// - `kill -SIGUSR2 <pid>` inspect golang GC
func waitSignalForShutdownServer(server *core.Server) {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGTERM, syscall.SIGUSR2, syscall.SIGUSR1, syscall.SIGINT)
ylog.Info("Listening SIGUSR1, SIGUSR2, SIGTERM/SIGINT...")
for p1 := range c {
ylog.Debug("Received signal", "signal", p1)
if p1 == syscall.SIGTERM || p1 == syscall.SIGINT {
ylog.Debug("graceful shutting down ...", "sign", p1)
// waiting for the server to finish processing the current request
server.Close()
os.Exit(0)
} else if p1 == syscall.SIGUSR2 {
var m runtime.MemStats
runtime.ReadMemStats(&m)
ylog.Debug("runtime stats", "gc_nums", m.NumGC)
} else if p1 == syscall.SIGUSR1 {
statsToLogger(server)
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/yomorun/yomo.git
git@gitee.com:yomorun/yomo.git
yomorun
yomo
yomo
master

搜索帮助