From 0f81ade06fbb06f8c6d02dd7584815f2b55257a4 Mon Sep 17 00:00:00 2001 From: Michael Desa Date: Wed, 20 Sep 2017 09:41:15 -0400 Subject: [PATCH] Set diagnsotic for main --- cmd/kapacitord/main.go | 4 +++- cmd/kapacitord/run/command.go | 4 +++- services/diagnostic/service.go | 8 ++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cmd/kapacitord/main.go b/cmd/kapacitord/main.go index 318a4e238..8a25b82ad 100644 --- a/cmd/kapacitord/main.go +++ b/cmd/kapacitord/main.go @@ -13,6 +13,7 @@ import ( "github.com/influxdata/kapacitor/cmd/kapacitord/help" "github.com/influxdata/kapacitor/cmd/kapacitord/run" + "github.com/influxdata/kapacitor/services/diagnostic" ) type Diagnostic run.Diagnostic @@ -56,6 +57,7 @@ type Main struct { // NewMain return a new instance of Main. func NewMain() *Main { return &Main{ + Diag: diagnostic.BootstrapMainHandler(), Stdin: os.Stdin, Stdout: os.Stdout, Stderr: os.Stderr, @@ -77,7 +79,7 @@ func (m *Main) Run(args ...string) error { cmd.Branch = branch err := cmd.Run(args...) - // Use logger from cmd since it may have special config now. + // Use diagnostic from cmd since it may have special config now. if cmd.Diag != nil { m.Diag = cmd.Diag } diff --git a/cmd/kapacitord/run/command.go b/cmd/kapacitord/run/command.go index fb930b862..e286807be 100644 --- a/cmd/kapacitord/run/command.go +++ b/cmd/kapacitord/run/command.go @@ -103,7 +103,9 @@ func (cmd *Command) Run(args ...string) error { // Initialize Logging Services cmd.diagService = diagnostic.NewService(config.Logging, cmd.Stdout, cmd.Stderr) - cmd.diagService.Open() + if err := cmd.diagService.Open(); err != nil { + return fmt.Errorf("failed to opend diagnostic service: %v", err) + } // Initialize cmd diagnostic cmd.Diag = cmd.diagService.NewCmdHandler() diff --git a/services/diagnostic/service.go b/services/diagnostic/service.go index 3e4d9a23c..9accf238d 100644 --- a/services/diagnostic/service.go +++ b/services/diagnostic/service.go @@ -40,6 +40,14 @@ func NewService(c Config, stdout, stderr io.Writer) *Service { } } +func BootstrapMainHandler() *CmdHandler { + s := NewService(NewConfig(), nil, os.Stderr) + // Should never error + _ = s.Open() + + return s.NewCmdHandler() +} + func (s *Service) SetLogLevelFromName(lvl string) error { s.mu.Lock() defer s.mu.Unlock()