-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
72 lines (60 loc) · 1.41 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
70
71
72
package main
import (
"context"
"flag"
"log"
"os"
"os/signal"
"syscall"
nomad "github.com/hashicorp/nomad/api"
"github.com/jorgemarey/nomad-log-shipper/output"
"github.com/jorgemarey/nomad-log-shipper/output/nats"
"github.com/jorgemarey/nomad-log-shipper/storage/boltdb"
)
const version = "0.2.2"
func main() {
var nodeID string
var dc string
flag.StringVar(&nodeID, "nodeID", "", "node to get allocations from")
flag.StringVar(&dc, "dc", "", "datacenter used to run this allocation")
flag.Parse()
client, err := nomad.NewClient(nomad.DefaultConfig())
if err != nil {
log.Fatal(err)
}
if nodeID == "" {
nodeID, err = getLocalNodeID(client)
if err != nil {
log.Fatal(err)
}
}
if dc == "" {
node, _, err := client.Nodes().Info(nodeID, nil)
if err != nil {
log.Fatal(err)
}
dc = node.Datacenter
}
store := boltdb.NewBoltDBStore()
agent, _ := NewAgent(nodeID, dc, newClient(client), outputs(), store) // wont fail
signalCh := make(chan os.Signal, 1)
signal.Notify(signalCh, syscall.SIGINT, syscall.SIGTERM)
go agent.Run()
select {
case s := <-signalCh:
log.Printf("Captured %v. Exiting...", s)
agent.Shutdown(context.Background())
}
}
func outputs() map[string]output.Output {
out, err := nats.NewNatsStreamingOutput()
if err != nil {
if err != nil {
log.Fatal(err)
}
}
return map[string]output.Output{
"log": out.Output("log"),
"span": out.Output("span"),
}
}