// Start runs the coprocess func (coprocess *Coprocess) Start() { log.Debugf("coprocess[%s].Start", coprocess.Name) fields := log.Fields{"process": "coprocess", "coprocess": coprocess.Name} stdout := utils.NewLogWriter(fields, log.InfoLevel) stderr := utils.NewLogWriter(fields, log.DebugLevel) coprocess.logWriters = []io.WriteCloser{stdout, stderr} defer coprocess.closeLogs() // always reset restartsRemain when we load the config coprocess.restartsRemain = coprocess.restartLimit for { if coprocess.restartLimit != unlimitedRestarts && coprocess.restartsRemain <= haltRestarts { break } cmd := utils.ArgsToCmd(coprocess.Args) coprocess.cmd = cmd cmd.Stdout = stdout cmd.Stderr = stderr if _, err := utils.ExecuteAndWait(cmd); err != nil { log.Errorf("coprocess[%s] exited: %s", coprocess.Name, err) } log.Debugf("coprocess[%s] exited", coprocess.Name) if !coprocess.restart { break } coprocess.restartsRemain-- } }
func (c *Command) setUpCmd(fields log.Fields) { cmd := ArgsToCmd(c.Exec, c.Args) if fields != nil { stdout := utils.NewLogWriter(fields, log.InfoLevel) stderr := utils.NewLogWriter(fields, log.DebugLevel) c.logWriters = []io.WriteCloser{stdout, stderr} cmd.Stdout = stdout cmd.Stderr = stderr } c.Cmd = cmd }
// PollAction runs the task func (t *Task) PollAction() { log.Debugf("task[%s].PollAction", t.Name) cmd := utils.ArgsToCmd(t.Args) t.cmd = cmd fields := log.Fields{"process": "task", "task": t.Name} stdout := utils.NewLogWriter(fields, log.InfoLevel) stderr := utils.NewLogWriter(fields, log.DebugLevel) t.logWriters = []io.WriteCloser{stdout, stderr} cmd.Stdout = stdout cmd.Stderr = stderr defer t.closeLogs() log.Debugf("task[%s].PollAction start", t.Name) if err := cmd.Start(); err != nil { log.Errorf("Unable to start task %s: %v", t.Name, err) return } t.run(cmd) log.Debugf("task[%s].PollAction complete", t.Name) }