forked from blind-oracle/cortex-tenant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (52 loc) · 1.18 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
package main
import (
"flag"
"os"
"os/signal"
"syscall"
"net/http"
_ "net/http/pprof"
log "github.com/sirupsen/logrus"
)
var (
version = "0.0.0"
)
func main() {
cfgFile := flag.String("config", "", "Path to a config file")
flag.Parse()
if *cfgFile == "" {
log.Fatalf("Config file required")
}
cfg, err := configLoad(*cfgFile)
if err != nil {
log.Fatal(err)
}
if cfg.ListenPprof != "" {
go func() {
if err := http.ListenAndServe(cfg.ListenPprof, nil); err != nil {
log.Fatalf("Unable to listen on %s: %s", cfg.ListenPprof, err)
}
}()
}
if cfg.LogLevel != "" {
lvl, err := log.ParseLevel(cfg.LogLevel)
if err != nil {
log.Fatalf("Unable to parse log level: %s", err)
}
log.SetLevel(lvl)
}
proc := newProcessor(*cfg)
if err = proc.run(); err != nil {
log.Fatalf("Unable to start: %s", err)
}
log.Warnf("Listening on %s, sending to %s", cfg.Listen, cfg.Target)
log.Warnf("Started v%s", version)
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGTERM, os.Interrupt)
<-ch
log.Warn("Shutting down, draining requests")
if err = proc.close(); err != nil {
log.Errorf("Error during shutdown: %s", err)
}
log.Warnf("Finished")
}