/
ghttp_server_admin_unix.go
59 lines (51 loc) · 1.31 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// 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/bjxujiang/gf.
// +build !windows
package ghttp
import (
"github.com/bjxujiang/gf/internal/intlog"
"os"
"os/signal"
"syscall"
)
// procSignalChan is the channel for listening the signal.
var procSignalChan = make(chan os.Signal)
// handleProcessSignal handles all signal from system.
func handleProcessSignal() {
var sig os.Signal
signal.Notify(
procSignalChan,
syscall.SIGINT,
syscall.SIGQUIT,
syscall.SIGKILL,
syscall.SIGTERM,
syscall.SIGABRT,
syscall.SIGUSR1,
syscall.SIGUSR2,
)
for {
sig = <-procSignalChan
intlog.Printf(`signal received: %s`, sig.String())
switch sig {
// Shutdown the servers.
case syscall.SIGINT, syscall.SIGQUIT, syscall.SIGKILL, syscall.SIGABRT:
shutdownWebServers(sig.String())
return
// Shutdown the servers gracefully.
// Especially from K8S when running server in POD.
case syscall.SIGTERM:
shutdownWebServersGracefully(sig.String())
return
// Restart the servers.
case syscall.SIGUSR1:
if err := restartWebServers(sig.String()); err != nil {
intlog.Error(err)
}
return
default:
}
}
}