-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
ghttp_server_admin_unix.go
41 lines (35 loc) · 1.04 KB
/
ghttp_server_admin_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// 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:/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()
}