-
Notifications
You must be signed in to change notification settings - Fork 0
/
serve.go
52 lines (43 loc) · 1.33 KB
/
serve.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
package commands
import (
"context"
"fmt"
"github.com/chef/automate/components/event-service/config"
"github.com/chef/automate/components/event-service/nats"
"github.com/chef/automate/components/event-service/server"
"github.com/chef/automate/lib/tracing"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
func newServeCmd() *cobra.Command {
return &cobra.Command{
Use: "serve",
Short: "Start the event gRPC server",
Run: func(cmd *cobra.Command, args []string) {
cfg, err := config.Configure()
if err != nil {
log.WithError(err).Fatal("Failed to configure event-service server")
}
uri := fmt.Sprintf("%s:%d", cfg.ServiceConfig.Host, cfg.ServiceConfig.Port)
log.WithFields(log.Fields{"uri": uri}).Info("Starting Event Service...")
closer, err := tracing.NewGlobalTracer("event-service")
if err != nil {
log.WithError(err).Warn("Failed to start tracer for event-service")
}
if closer != nil {
defer tracing.CloseQuietly(closer)
}
// Start a NATs Server only if the feature was enabled through the config
// @afiune should this replace the event-service?
if cfg.StreamService.Enabled {
go func() {
err := nats.Spawn(cfg)
if err != nil {
log.Fatalf("failed starting NATS: %+v", err)
}
}()
}
server.StartGRPC(context.Background(), cfg)
},
}
}