forked from tinkerbell/smee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
97 lines (84 loc) · 2.12 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"flag"
"time"
"github.com/packethost/pkg/env"
"github.com/packethost/pkg/log"
"github.com/pkg/errors"
"github.com/tinkerbell/boots/conf"
"github.com/tinkerbell/boots/dhcp"
"github.com/tinkerbell/boots/httplog"
"github.com/tinkerbell/boots/installers"
"github.com/tinkerbell/boots/job"
"github.com/tinkerbell/boots/metrics"
"github.com/tinkerbell/boots/packet"
"github.com/tinkerbell/boots/syslog"
"github.com/tinkerbell/boots/tftp"
_ "github.com/tinkerbell/boots/installers/coreos"
_ "github.com/tinkerbell/boots/installers/custom_ipxe"
_ "github.com/tinkerbell/boots/installers/nixos"
_ "github.com/tinkerbell/boots/installers/osie"
_ "github.com/tinkerbell/boots/installers/rancher"
_ "github.com/tinkerbell/boots/installers/vmware"
"github.com/avast/retry-go"
)
var (
client *packet.Client
apiBaseURL = env.URL("API_BASE_URL", "https://api.packet.net")
mainlog log.Logger
GitRev = "unknown (use make)"
StartTime = time.Now()
)
func main() {
flag.Parse()
l, err := log.Init("github.com/tinkerbell/boots")
if err != nil {
panic(nil)
}
defer l.Close()
mainlog = l.Package("main")
metrics.Init(l)
dhcp.Init(l)
conf.Init(l)
httplog.Init(l)
installers.Init(l)
job.Init(l)
syslog.Init(l)
tftp.Init(l)
mainlog.With("version", GitRev).Info("starting")
consumer := env.Get("API_CONSUMER_TOKEN")
if consumer == "" {
err := errors.New("required envvar missing")
mainlog.With("envvar", "API_CONSUMER_TOKEN").Fatal(err)
panic(err)
}
auth := env.Get("API_AUTH_TOKEN")
if auth == "" {
err := errors.New("required envvar missing")
mainlog.With("envvar", "API_AUTH_TOKEN").Fatal(err)
panic(err)
}
client, err = packet.NewClient(consumer, auth, apiBaseURL)
if err != nil {
mainlog.Fatal(err)
}
job.SetClient(client)
go func() {
mainlog.Info("serving syslog")
err = retry.Do(
func() error {
_, err := syslog.StartReceiver(1)
return err
},
)
if err != nil {
mainlog.Fatal(errors.Wrap(err, "retry syslog serve"))
}
}()
mainlog.Info("serving tftp")
go ServeTFTP()
mainlog.Info("serving dhcp")
go ServeDHCP()
mainlog.Info("serving http")
ServeHTTP()
}