Skip to content

Commit

Permalink
fix: Program starts with syntax error, ensure re-run occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
PatKoperwas committed Feb 2, 2018
1 parent 34331fa commit 4117b9e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
7 changes: 4 additions & 3 deletions tychus/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 0 additions & 2 deletions tychus/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 16 additions & 10 deletions tychus/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down

0 comments on commit 4117b9e

Please sign in to comment.