-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
104 lines (85 loc) · 1.73 KB
/
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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"syscall"
"github.com/shanghai-edu/n9e-probe/config"
"github.com/shanghai-edu/n9e-probe/http"
"github.com/shanghai-edu/n9e-probe/probe"
"github.com/shanghai-edu/n9e-probe/probe/core"
"github.com/toolkits/pkg/file"
"github.com/toolkits/pkg/logger"
"github.com/toolkits/pkg/runner"
)
var (
vers *bool
help *bool
conf *string
)
func init() {
vers = flag.Bool("v", false, "display the version.")
help = flag.Bool("h", false, "print this help.")
conf = flag.String("f", "", "specify configuration file.")
flag.Parse()
if *vers {
fmt.Println("version:", config.Version)
os.Exit(0)
}
if *help {
flag.Usage()
os.Exit(0)
}
}
func main() {
aconf()
pconf()
start()
cfg := config.Get()
config.InitLog(cfg.Logger)
core.InitRpcClients()
probe.BuildMappers()
probe.Collect()
http.Start()
ending()
}
// auto detect configuration file
func aconf() {
if *conf != "" && file.IsExist(*conf) {
return
}
*conf = "etc/probe.local.yml"
if file.IsExist(*conf) {
return
}
*conf = "etc/probe.yml"
if file.IsExist(*conf) {
return
}
fmt.Println("no configuration file for probe")
os.Exit(1)
}
// parse configuration file
func pconf() {
if err := config.Parse(*conf); err != nil {
fmt.Println("cannot parse configuration file:", err)
os.Exit(1)
}
}
func ending() {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
select {
case <-c:
fmt.Printf("stop signal caught, stopping... pid=%d\n", os.Getpid())
}
logger.Close()
http.Shutdown()
fmt.Println("probe stopped successfully")
}
func start() {
runner.Init()
fmt.Println("probe start, use configuration file:", *conf)
fmt.Println("runner.cwd:", runner.Cwd)
}