From 8eb140540f3cee41ac72f3c354b6c3c124c65da8 Mon Sep 17 00:00:00 2001 From: Ryan Bourgeois Date: Mon, 2 Dec 2013 14:45:56 -0800 Subject: [PATCH] Don't send Running before Backoff. --- service/service.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/service/service.go b/service/service.go index 4797216..0dad2de 100644 --- a/service/service.go +++ b/service/service.go @@ -196,26 +196,27 @@ func (s *Service) Run(commands <-chan Command, events chan<- Event) { sendEvent(Starting, nil) go func() { s.command = s.makeCommand() - startTime := time.Now() if err := s.command.Start(); err == nil { - states <- ProcessState{Running, nil} - exitErr := s.command.Wait() + time.Sleep(s.StartTimeout) msg := "" - if time.Now().Sub(startTime) < s.StartTimeout { - if exitErr == nil { - msg = "process exited prematurely with success" - } else { - msg = fmt.Sprintf("process exited prematurely with failure: %s", exitErr) - } - states <- ProcessState{Backoff, ExitError(msg)} - } else { + if s.Pid() > 0 { + states <- ProcessState{Running, nil} + exitErr := s.command.Wait() if exitErr == nil { msg = "process exited normally with success" } else { msg = fmt.Sprintf("process exited normally with failure: %s", exitErr) } states <- ProcessState{Exited, ExitError(msg)} + } else { + exitErr := s.command.Wait() + if exitErr == nil { + msg = "process exited prematurely with success" + } else { + msg = fmt.Sprintf("process exited prematurely with failure: %s", exitErr) + } + states <- ProcessState{Backoff, ExitError(msg)} } } else { states <- ProcessState{Exited, err}