-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
executable file
·55 lines (45 loc) · 996 Bytes
/
main.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
package main
import (
"flag"
"fmt"
"log"
"os"
"os/signal"
"syscall"
"github.com/sirupsen/logrus"
)
var (
Config ProxyConfig
Log *logrus.Logger
configFile = flag.String("c", "./conf.yaml", "配置文件:conf.yaml")
)
func onExitSignal() {
signalChan := make(chan os.Signal)
// 监听系统服务退出信号
signal.Notify(signalChan, syscall.SIGUSR1, syscall.SIGTERM, syscall.SIGINT, os.Kill)
for {
signal := <-signalChan
log.Println("Get Signal:%v\r\n", signal)
switch signal {
case syscall.SIGTERM, syscall.SIGINT, os.Kill:
log.Fatal("系统退出。。。")
}
}
}
func main() {
flag.Parse()
fmt.Println("Start Proxy...")
// 解析配置
parseConfigFile(*configFile)
// 初始化日志模块
initLogger()
// 初始化代理的服务
initBackendSvrs(Config.Backend)
// 系统退出信号监听
go onExitSignal()
// 初始化状态服务
initStats()
fmt.Println("Start Successful...")
// 初始化代理服务
initProxy()
}