-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmain.go
44 lines (40 loc) · 887 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
package main
import (
"context"
"flag"
"github.com/golang/glog"
c "github.com/mayuresh82/gocast/config"
"github.com/mayuresh82/gocast/controller"
"github.com/mayuresh82/gocast/server"
log "github.com/sirupsen/logrus"
"os"
"os/signal"
"syscall"
)
var (
config = flag.String("config", "", "Path to config file")
)
func main() {
flag.Parse()
if glog.V(4) {
log.SetLevel(log.DebugLevel)
}
conf := c.GetConfig(*config)
mon := controller.NewMonitor(conf)
srv := server.NewServer(conf.Agent.ListenAddr, mon)
ctx, cancel := context.WithCancel(context.Background())
// catch interrupt
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, os.Interrupt, syscall.SIGHUP, syscall.SIGTERM)
go func() {
for {
sig := <-signalChan
if sig == os.Interrupt || sig == syscall.SIGTERM {
mon.CloseAll()
cancel()
return
}
}
}()
srv.Serve(ctx)
}