forked from open-falcon-archive/graph
/
main.go
83 lines (66 loc) · 1.48 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
package main
import (
"flag"
"fmt"
"log"
"os"
"os/signal"
"syscall"
"github.com/open-falcon/graph/api"
"github.com/open-falcon/graph/cron"
"github.com/open-falcon/graph/g"
"github.com/open-falcon/graph/http"
"github.com/open-falcon/graph/index"
"github.com/open-falcon/graph/rrdtool"
)
func start_signal(pid int, conf g.GlobalConfig) {
sigs := make(chan os.Signal, 1)
log.Println(pid, "register signal notify")
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
for {
s := <-sigs
log.Println("recv", s)
switch s {
case syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT:
log.Println("gracefull shut down")
http.Close_chan <- 1
api.Close_chan <- 1
cron.Out_done_chan <- 1
<-http.Close_done_chan
<-api.Close_done_chan
log.Println(pid, "remove ", conf.Pid)
os.Remove(conf.Pid)
rrdtool.FlushAll()
log.Println(pid, "flush done, exiting")
os.Exit(0)
}
}
}
func main() {
cfg := flag.String("c", "cfg.json", "configuration file")
version := flag.Bool("v", false, "show version")
versionGit := flag.Bool("vg", false, "show version")
flag.Parse()
if *version {
fmt.Println(g.VERSION)
os.Exit(0)
}
if *versionGit {
fmt.Println(g.VERSION, g.COMMIT)
os.Exit(0)
}
// global config
g.ParseConfig(*cfg)
// init db
g.InitDB()
// start rrdtool
rrdtool.Start()
go api.Start()
// 刷硬盘
go cron.SyncDisk()
// 索引更新2.0
index.Start()
// http
go http.Start()
start_signal(os.Getpid(), *g.Config())
}