mirror of
https://gitee.com/johng/gf.git
synced 2024-11-30 11:18:02 +08:00
42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
|
//
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
// If a copy of the MIT was not distributed with this file,
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
//go:build !windows
|
|
// +build !windows
|
|
|
|
package ghttp
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"syscall"
|
|
|
|
"github.com/gogf/gf/v2/internal/intlog"
|
|
"github.com/gogf/gf/v2/os/glog"
|
|
"github.com/gogf/gf/v2/os/gproc"
|
|
)
|
|
|
|
// handleProcessSignal handles all signals from system in blocking way.
|
|
func handleProcessSignal() {
|
|
var ctx = context.TODO()
|
|
gproc.AddSigHandlerShutdown(func(sig os.Signal) {
|
|
shutdownWebServersGracefully(ctx, sig)
|
|
})
|
|
gproc.AddSigHandler(func(sig os.Signal) {
|
|
// If the graceful restart feature is not enabled,
|
|
// it does nothing except printing a warning log.
|
|
if !gracefulEnabled {
|
|
glog.Warning(ctx, "graceful reload feature is disabled")
|
|
return
|
|
}
|
|
if err := restartWebServers(ctx, sig, ""); err != nil {
|
|
intlog.Errorf(ctx, `%+v`, err)
|
|
}
|
|
}, syscall.SIGUSR1)
|
|
|
|
gproc.Listen()
|
|
}
|