/
radon.go
81 lines (65 loc) · 1.31 KB
/
radon.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Radon
*
* Copyright 2018 The Radon Authors.
* Code is licensed under the GPLv3.
*
*/
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"runtime"
"syscall"
"build"
"config"
"ctl"
"monitor"
"proxy"
"github.com/xelabs/go-mysqlstack/xlog"
)
var (
flagConf string
)
func init() {
flag.StringVar(&flagConf, "c", "", "radon config file")
flag.StringVar(&flagConf, "config", "", "radon config file")
}
func usage() {
fmt.Println("Usage: " + os.Args[0] + " [-c|--config] <radon-config-file>")
}
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
log := xlog.NewStdLog(xlog.Level(xlog.DEBUG))
build := build.GetInfo()
fmt.Printf("radon:[%+v]\n", build)
// config
flag.Usage = func() { usage() }
flag.Parse()
if flagConf == "" {
usage()
os.Exit(0)
}
conf, err := config.LoadConfig(flagConf)
if err != nil {
log.Panic("radon.load.config.error[%v]", err)
}
log.SetLevel(conf.Log.Level)
// Monitor
monitor.Start(log, conf)
// Proxy.
proxy := proxy.NewProxy(log, flagConf, build.Tag, conf)
proxy.Start()
// Admin portal.
admin := ctl.NewAdmin(log, proxy)
admin.Start()
// Handle SIGINT and SIGTERM.
ch := make(chan os.Signal)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
log.Info("radon.signal:%+v", <-ch)
// Stop the proxy and httpserver.
proxy.Stop()
admin.Stop()
}