@@ -172,35 +172,37 @@ func Status() (isRunning bool, pr *os.Process, e error) {
172172// If daemonized process keeps running after timeout seconds passed
173173// then process seems to be successfully started.
174174//
175- // Note, that this function can return success=false and e=nil.
176- // That's a case when application successfully started,
177- // but stops before timeout seconds passed.
178- //
179175// This function can also be used when writing your own daemon actions.
180- func Start (timeout uint8 ) (success bool , e error ) {
181- path , e := filepath .Abs (AppPath )
182- if e != nil {
176+ func Start (timeout uint8 ) (e error ) {
177+ const errLoc = "daemonigo.Start()"
178+ path , err := filepath .Abs (AppPath )
179+ if err != nil {
180+ e = fmt .Errorf ("%s: failed to resolve absolute path of %s, reason -> %s" , errLoc , AppName , err .Error ())
183181 return
184182 }
185183 cmd := exec .Command (path )
186184 cmd .Env = append (
187185 os .Environ (),
188186 fmt .Sprintf ("%s=%s" , EnvVarName , EnvVarValue ),
189187 )
190- if e = cmd .Start (); e != nil {
188+ if err = cmd .Start (); err != nil {
189+ e = fmt .Errorf ("%s: failed to start %s, reason -> %s" , errLoc , AppName , err .Error ())
191190 return
192191 }
193192 select {
194193 case <- func () chan bool {
195194 ch := make (chan bool )
196195 go func () {
197- e = cmd .Wait ()
196+ if err := cmd .Wait (); err != nil {
197+ e = fmt .Errorf ("%s: %s running failed, reason -> %s" , errLoc , AppName , err .Error ())
198+ } else {
199+ e = fmt .Errorf ("%s: %s stopped and not running" , errLoc , AppName )
200+ }
198201 ch <- true
199202 }()
200203 return ch
201204 }():
202205 case <- time .After (time .Duration (timeout ) * time .Second ):
203- success = true
204206 }
205207 return
206208}
0 commit comments