-
Notifications
You must be signed in to change notification settings - Fork 1
/
bgpcommander.go
65 lines (53 loc) · 1.58 KB
/
bgpcommander.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
package main
import (
"bufio"
"flag"
"github.com/coreos/go-etcd/etcd"
"github.com/crazed/bgpcommander/node_state"
"os"
"os/signal"
"strings"
"syscall"
)
func readStdin(state *node_state.NodeState) {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
state.ProcessExaBGPOutput(scanner.Bytes())
}
}
func handleSignal(signals chan os.Signal, state *node_state.NodeState) {
<-signals
state.Shutdown()
os.Exit(0)
}
type machines []string
func (m *machines) String() string {
return strings.Join(*m, ", ")
}
func (m *machines) Set(value string) error {
for _, machine := range strings.Split(value, ",") {
*m = append(*m, strings.TrimSpace(machine))
}
return nil
}
func main() {
cluster := machines{"http://127.0.0.1:4001"}
healthcheckScriptPath := "/tmp"
hostname, _ := os.Hostname()
flag.Var(&cluster, "c", "Comma separated list of etcd cluster members")
flag.StringVar(&healthcheckScriptPath, "p", healthcheckScriptPath, "Path to store healthcheck scripts")
flag.StringVar(&hostname, "n", hostname, "Override node's name")
flag.Parse()
client := etcd.NewClient(cluster)
state := node_state.NewNodeState(hostname, client, true, healthcheckScriptPath)
state.Logger.Println("Using etcd servers:", cluster.String())
state.Logger.Println("Using node name:", hostname)
state.Logger.Println("Using healthcheck script path:", healthcheckScriptPath)
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGTERM, syscall.SIGINT)
go readStdin(state)
go handleSignal(signals, state)
state.WatchKeys()
// goroutines are doing the work, so block here
select {}
}