From 4117b9e88ad3b6221c65353a039653767e8a2eef Mon Sep 17 00:00:00 2001 From: Patrick Koperwas Date: Fri, 2 Feb 2018 09:46:05 -0800 Subject: [PATCH] fix: Program starts with syntax error, ensure re-run occurs --- tychus/orchestrator.go | 7 ++++--- tychus/proxy.go | 2 -- tychus/runner.go | 26 ++++++++++++++++---------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/tychus/orchestrator.go b/tychus/orchestrator.go index 06c1ebe..db440b8 100644 --- a/tychus/orchestrator.go +++ b/tychus/orchestrator.go @@ -48,9 +48,10 @@ func (o *Orchestrator) Start() error { o.config.Logger.Debug("Request started") modified := o.watcher.scan() - if modified { - err := o.runner.run() - if err != nil { + if modified || o.proxy.mode == mode_errored { + o.config.Logger.Debug("Rerunnning") + + if err := o.runner.run(); err != nil { o.proxy.error(err) continue } diff --git a/tychus/proxy.go b/tychus/proxy.go index 9f4a798..42b7790 100644 --- a/tychus/proxy.go +++ b/tychus/proxy.go @@ -62,8 +62,6 @@ func (p *proxy) start() error { strconv.Itoa(p.config.AppPort), ) - p.serve() - err = server.Serve(listener) if err != nil { return err diff --git a/tychus/runner.go b/tychus/runner.go index f335421..85649f5 100644 --- a/tychus/runner.go +++ b/tychus/runner.go @@ -29,11 +29,24 @@ func newRunner(c *Configuration, args []string) *runner { func (r *runner) run() error { r.kill() + if err := r.execute(); err != nil { + return err + } + + if r.config.Wait { + r.wait() + } else { + go r.wait() + } + + return nil +} + +func (r *runner) execute() error { if r.cmd != nil && r.cmd.ProcessState != nil && r.cmd.ProcessState.Exited() { return nil } - var stderr bytes.Buffer r.stderr = &bytes.Buffer{} mw := io.MultiWriter(r.stderr, os.Stderr) @@ -45,15 +58,8 @@ func (r *runner) run() error { // process that it may spawn. r.cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} - err := r.cmd.Start() - if err != nil { - return errors.New(stderr.String()) - } - - if r.config.Wait { - r.wait() - } else { - go r.wait() + if err := r.cmd.Start(); err != nil { + return errors.New(r.stderr.String()) } return nil