Skip to content

Commit

Permalink
Merge pull request elastic#5 from tsg/simplifymain
Browse files Browse the repository at this point in the history
Simplify the main function.
  • Loading branch information
monicasarbu committed Aug 20, 2015
2 parents 19db604 + 21458fe commit 5dc2f00
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,8 @@ func (t *Topbeat) Stop() {
t.isAlive = false
}

func (t *Topbeat) IsAlive() bool {

return t.isAlive
}

func main() {

over := make(chan bool)

// Use our own FlagSet, because some libraries pollute the global one
var cmdLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)

Expand Down Expand Up @@ -243,7 +236,6 @@ func main() {
}

topbeat := &Topbeat{}

if err = topbeat.Init(Config.Input, publisher.Publisher.Queue); err != nil {
logp.Critical(err.Error())
os.Exit(1)
Expand All @@ -257,16 +249,6 @@ func main() {
}
service.BeforeRun()

// run the Beat code in background
go func() {
err := topbeat.Run()
if err != nil {
logp.Critical("Sniffer main loop failed: %v", err)
os.Exit(1)
}
over <- true
}()

service.HandleSignals(topbeat.Stop)

// Startup successful, disable stderr logging if requested by
Expand All @@ -275,11 +257,10 @@ func main() {

logp.Debug("main", "Starting topbeat")

// Wait for the goroutines to finish
for _ = range over {
if !topbeat.IsAlive() {
break
}
err = topbeat.Run()
if err != nil {
logp.Critical("Sniffer main loop failed: %v", err)
os.Exit(1)
}

logp.Debug("main", "Cleanup")
Expand Down

0 comments on commit 5dc2f00

Please sign in to comment.