/
ghttp_server_admin_unix.go
49 lines (42 loc) · 1.16 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
// Copyright 2017 gf Author(https://gitee.com/johng/gf). 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://gitee.com/johng/gf.
// +build !windows
package ghttp
import (
"os"
"syscall"
"os/signal"
)
// 进程信号量监听消息队列
var procSignalChan = make(chan os.Signal)
// 信号量处理
func handleProcessSignal() {
var sig os.Signal
signal.Notify(
procSignalChan,
syscall.SIGINT,
syscall.SIGQUIT,
syscall.SIGKILL,
syscall.SIGHUP,
syscall.SIGTERM,
syscall.SIGUSR1,
syscall.SIGUSR2,
)
for {
sig = <- procSignalChan
switch sig {
// 进程终止,停止所有子进程运行
case syscall.SIGINT, syscall.SIGQUIT, syscall.SIGKILL, syscall.SIGHUP, syscall.SIGTERM:
shutdownWebServers(true)
return
// 用户信号,重启服务
case syscall.SIGUSR1:
restartWebServers(true)
return
default:
}
}
}