forked from open-falcon-archive/graph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
82 lines (69 loc) · 1.53 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
package main
import (
"flag"
"fmt"
"log"
"os"
"os/signal"
"syscall"
"github.com/open-falcon/graph/api"
"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, cfg *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")
if cfg.Http.Enabled {
http.Close_chan <- 1
<-http.Close_done_chan
}
log.Println("http stop ok")
if cfg.Rpc.Enabled {
api.Close_chan <- 1
<-api.Close_done_chan
}
log.Println("rpc stop ok")
rrdtool.Out_done_chan <- 1
rrdtool.FlushAll()
log.Println("rrdtool stop ok")
log.Println(pid, "exit")
os.Exit(0)
}
}
}
func main() {
cfg := flag.String("c", "cfg.json", "specify config file")
version := flag.Bool("v", false, "show version")
versionGit := flag.Bool("vg", false, "show version and git commit log")
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()
// start api
go api.Start()
// start indexing
index.Start()
// start http server
go http.Start()
start_signal(os.Getpid(), g.Config())
}