-
Notifications
You must be signed in to change notification settings - Fork 33
/
main.go
60 lines (48 loc) · 1.55 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
package main
import (
"net/http"
"github.com/allegro/marathon-consul/config"
"github.com/allegro/marathon-consul/consul"
"github.com/allegro/marathon-consul/marathon"
"github.com/allegro/marathon-consul/metrics"
"github.com/allegro/marathon-consul/sentry"
"github.com/allegro/marathon-consul/sse"
"github.com/allegro/marathon-consul/sync"
"github.com/allegro/marathon-consul/web"
log "github.com/sirupsen/logrus"
)
var VERSION string
func main() {
log.WithField("Version", VERSION).Info("Starting marathon-consul")
config, err := config.New()
if err != nil {
log.Fatal(err.Error())
}
config.Log.Sentry.Release = VERSION
if sentryErr := sentry.Init(config.Log.Sentry); sentryErr != nil {
log.Fatal(sentryErr)
}
err = metrics.Init(config.Metrics)
if err != nil {
log.Fatal(err.Error())
}
consulInstance := consul.New(config.Consul)
// TODO(tz) - move Leader from sync module to highest level config, access like config.Leader
remote, err := marathon.New(config.Marathon)
if err != nil {
log.Fatal(err.Error())
}
sync.New(config.Sync, remote, consulInstance, consulInstance.AddAgentsFromApps).StartSyncServicesJob()
//TODO: Use context instead of stop function.
var stopSSE sse.Stop
go func() {
stopSSE, err = sse.NewHandler(config.SSE, config.Web, remote, consulInstance)
if err != nil {
log.WithError(err).Fatal("Cannot instantiate SSE handler")
}
}()
defer stopSSE()
http.HandleFunc("/health", web.HealthHandler)
log.WithField("Port", config.Web.Listen).Info("Listening")
log.Fatal(http.ListenAndServe(config.Web.Listen, nil))
}