From 101dbd22da730e8be686ce972807c7dcb3771334 Mon Sep 17 00:00:00 2001 From: Dennis Bellinger Date: Mon, 18 Jul 2016 18:11:10 -0400 Subject: [PATCH] Merged service.go into telegraf.go Due to compilation issues on Windows, moved the code from service.go into telegraf.go and removed service.go entirely. --- cmd/telegraf/service.go | 53 ---------------------------------------- cmd/telegraf/telegraf.go | 46 ++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 53 deletions(-) delete mode 100644 cmd/telegraf/service.go diff --git a/cmd/telegraf/service.go b/cmd/telegraf/service.go deleted file mode 100644 index 4fa699c2b..000000000 --- a/cmd/telegraf/service.go +++ /dev/null @@ -1,53 +0,0 @@ -// Run the telegraf data collector -package main - -import ( - "log" - - "github.com/kardianos/service" -) - -var logger service.Logger - -var stop chan struct{} - -var srvc service.Service - -type program struct{} - -func (p *program) Start(s service.Service) error { - srvc = s - go p.run() - return nil -} -func (p *program) run() { - stop = make(chan struct{}) - reloadLoop(stop, srvc) -} -func (p *program) Stop(s service.Service) error { - close(stop) - return nil -} - -func main() { - svcConfig := &service.Config{ - Name: "telegraf", - DisplayName: "Telegraf Data Collector Service", - Description: "Collects data using a series of plugins and publishes it to" + - "another series of plugins.", - } - - prg := &program{} - s, err := service.New(prg, svcConfig) - if err != nil { - log.Fatal(err) - } - logger, err = s.Logger(nil) - if err != nil { - log.Fatal(err) - } - err = s.Run() - if err != nil { - logger.Error(err) - } -} diff --git a/cmd/telegraf/telegraf.go b/cmd/telegraf/telegraf.go index 766a91c2e..49aac13f7 100644 --- a/cmd/telegraf/telegraf.go +++ b/cmd/telegraf/telegraf.go @@ -104,6 +104,15 @@ Examples: telegraf -config telegraf.conf -input-filter cpu:mem -output-filter influxdb ` +var logger service.Logger + +var stop chan struct{} + +var srvc service.Service + +type program struct{} + + func reloadLoop(stop chan struct{}, s service.Service) { defer func() { if service.Interactive() { @@ -301,3 +310,40 @@ func usageExit(rc int) { fmt.Println(usage) os.Exit(rc) } + +func (p *program) Start(s service.Service) error { + srvc = s + go p.run() + return nil +} +func (p *program) run() { + stop = make(chan struct{}) + reloadLoop(stop, srvc) +} +func (p *program) Stop(s service.Service) error { + close(stop) + return nil +} + +func main() { + svcConfig := &service.Config{ + Name: "telegraf", + DisplayName: "Telegraf Data Collector Service", + Description: "Collects data using a series of plugins and publishes it to" + + "another series of plugins.", + } + + prg := &program{} + s, err := service.New(prg, svcConfig) + if err != nil { + log.Fatal(err) + } + logger, err = s.Logger(nil) + if err != nil { + log.Fatal(err) + } + err = s.Run() + if err != nil { + logger.Error(err) + } +}