-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
55 lines (46 loc) · 1.34 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
package main
import (
"flag"
"github.com/OpsKitchen/ok_agent/model/config"
"github.com/OpsKitchen/ok_agent/util"
"github.com/Sirupsen/logrus"
"time"
)
func main() {
//parse config file from cli argument
baseConfigFile := flag.String("c", "/etc/ok_agent.json", "base config file path")
debugAgent := flag.Bool("d", false, "enable debug mode")
debugApi := flag.Bool("debug-api", false, "enable open api debug log")
flag.Parse()
//enable agent debug mode
if *debugAgent {
util.Logger.Level = logrus.DebugLevel
}
//enable api log
if *debugApi {
util.ApiLogger.Level = logrus.DebugLevel
}
//prepare config
if util.FileExist(*baseConfigFile) {
if err := util.ParseJsonFile(*baseConfigFile, config.B); err != nil {
util.Logger.Fatal("can not parse base config file: " + err.Error())
}
}
//prepare credential
if !util.FileExist(config.B.CredentialFile) {
util.Logger.Fatal("credential file not found.")
}
if err := util.ParseJsonFile(config.B.CredentialFile, config.C); err != nil {
util.Logger.Fatal("credential file pasring error: " + err.Error())
}
//check log dir
if err := util.PrepareLogFile(); err != nil {
util.Logger.Fatal("can not open or create log file: " + err.Error())
}
//prepare api client
util.PrepareApiClient()
//dispatch
for d := new(Dispatcher); ; time.Sleep(10 * time.Second) {
d.Dispatch()
}
}