-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (36 loc) · 847 Bytes
/
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
package main
import (
"os"
"os/signal"
"syscall"
"alarm_monitor/business"
"alarm_monitor/config"
"alarm_monitor/model/mysql"
"alarm_monitor/server"
"github.com/cihub/seelog"
)
func main() {
defer destroy()
s := server.NewServer()
cfg := config.GetConfig()
kafka, err := business.NewKafka(cfg.Kafka.Brokers, cfg.Kafka.ReceiveAlarmTopic)
if err != nil {
seelog.Errorf("new kafka err: %v", err)
return
}
s.Kafkas = append(s.Kafkas, kafka)
s.Start()
sc := make(chan os.Signal, 1)
signal.Notify(sc, os.Kill, os.Interrupt, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
select {
case n := <-sc:
seelog.Infof("receive signal %v, closing", n)
case <-s.Ctx().Done():
seelog.Infof("context is done with %v, closing", s.Ctx().Err())
}
s.Stop()
}
func destroy() {
mysql.FreeDB()
seelog.Flush()
}