-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
69 lines (57 loc) · 1.4 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
package main
import (
"os"
"os/signal"
"syscall"
log "github.com/sirupsen/logrus"
"gopkg.in/alecthomas/kingpin.v2"
)
var (
debug = kingpin.Flag("debug", "Debug mode.").Bool()
configFile = kingpin.Flag("config.file", "path to the config file").Required().String()
metricsListenAddr = kingpin.Flag("metrics.listen-addr", "listen address for metrics webserver").Default("127.0.0.1:9144").String()
)
func main() {
config := &Config{}
tailers := NewSafeTailers()
kingpin.Parse()
if *debug {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
}
log.SetFormatter(&log.TextFormatter{
DisableColors: true,
FullTimestamp: true,
})
go func() {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP)
for {
select {
case <-c:
log.WithFields(log.Fields{"configFile": *configFile}).Info("SIGHUP received, " +
"reloading config file")
err := config.load(*configFile)
if err != nil {
log.Warnf("Unable to load configuration file: '%s'. Skipping configuration reload and "+
"keeping current configuration", *configFile)
break
}
err = runTailer(config, *configFile, tailers)
if err != nil {
log.Fatal(err)
}
}
}
}()
err := config.load(*configFile)
if err != nil {
log.Fatal(err)
}
err = runTailer(config, *configFile, tailers)
if err != nil {
log.Fatal(err)
}
runServer(*metricsListenAddr)
}