-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathnetcore.go
58 lines (48 loc) · 1.28 KB
/
netcore.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
package main
import (
"flag"
"log"
"os"
"strings"
)
var etcdServers = flag.String("etcd", "", "Comma-separated list of etcd servers.")
func init() {
flag.Parse()
}
func main() {
if len(*etcdServers) == 0 {
if len(os.Getenv("ETCD_PORT")) > 0 {
*etcdServers = strings.Replace(os.Getenv("ETCD_PORT"), "tcp://", "http://", 1)
} else {
*etcdServers = "etcd" // just some default hostname that Docker or otherwise might use
}
}
db := NewEtcdDB(*etcdServers)
log.Println("PRECONFIG")
cfg, err := db.GetConfig()
log.Println("POSTCONFIG")
if err != nil {
log.Printf("Configuration failed: %s\n", err)
os.Exit(1)
}
var dhcpExit chan error
if cfg.DHCPIP() == nil {
log.Println("DHCP service is disabled; this machine does not have a DHCP IP assigned.")
} else if cfg.DHCPSubnet() == nil {
log.Println("DHCP service is disabled; this machine's zone does not have a DHCP subnet assigned.")
} else if cfg.DHCPNIC() == "" {
log.Println("DHCP service is disabled; this machine does not have a DHCP NIC assigned.")
} else {
dhcpExit = dhcpSetup(cfg)
}
dnsExit := dnsSetup(cfg)
log.Println("NETCORE Started.")
select {
case err := <-dhcpExit:
log.Printf("DHCP Exited: %s\n", err)
os.Exit(1)
case err := <-dnsExit:
log.Printf("DNS Exited: %s\n", err)
os.Exit(1)
}
}