diff --git a/main.go b/main.go index 1819d77..d219aa1 100644 --- a/main.go +++ b/main.go @@ -44,8 +44,6 @@ func main() { me.pollDelay = 3 * time.Second me.failcountmax = 20 // die every minute if zookeeper can't be found - // me.machine.ConfigLoad() - me.forge = forgepb.InitPB() me.machine = zoopb.InitMachine() diff --git a/watchdog.go b/watchdog.go index f42e516..66bed5f 100644 --- a/watchdog.go +++ b/watchdog.go @@ -20,6 +20,21 @@ func NewWatchdog() { me.dog = time.NewTicker(me.pollDelay) defer me.dog.Stop() done := make(chan bool) + for { + select { + case <-done: + fmt.Println("Done!") + return + case _ = <-me.dog.C: + s := me.machine.UpdatePackages() + me.failcount += 1 + sendMachine(s) + + if me.failcount > 20 { + os.Exit(0) + } + } + } /* // this example would exit/destroy the ticker in 10 seconds go func() { @@ -27,23 +42,4 @@ func NewWatchdog() { done <- true }() */ - for { - select { - case <-done: - fmt.Println("Done!") - return - case _ = <-me.dog.C: - // log.Info("Watchdog() ticked", me.zookeeper, "Current time: ", t) - s := me.machine.UpdatePackages() - // pingStatus() - me.failcount += 1 - sendMachine(s) - - if me.failcount > 20 { - os.Exit(0) - } - // h.pollHypervisor() - // h.Scan() - } - } }