示例#1
0
// 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--
	}
}
示例#2
0
// OnChange runs the backend's onChange command, returning the results
func (b *Backend) OnChange() (int, error) {
	defer func() {
		// reset command object because it can't be reused
		b.onChangeCmd = utils.ArgsToCmd(b.onChangeCmd.Args)
	}()

	exitCode, err := utils.RunWithFields(b.onChangeCmd, log.Fields{"process": "OnChange", "backend": b.Name})
	return exitCode, err
}
func getSignalTestConfig() *App {
	service, _ := services.NewService(
		"test-service", 1, 1, 1, nil, nil, &NoopServiceBackend{})
	app := EmptyApp()
	app.Command = utils.ArgsToCmd([]string{
		"./testdata/test.sh",
		"interruptSleep"})
	app.StopTimeout = 5
	app.Services = []*services.Service{service}
	return app
}
示例#4
0
func (s *Sensor) observe() (string, error) {
	defer func() {
		// reset command object because it can't be reused
		s.checkCmd = utils.ArgsToCmd(s.checkCmd.Args)
	}()

	// we'll pass stderr to the container's stderr, but stdout must
	// be "clean" and not have anything other than what we intend
	// to write to our collector.
	s.checkCmd.Stderr = os.Stderr
	out, err := s.checkCmd.Output()
	if err != nil {
		return "", err
	}
	return string(out[:]), nil
}
示例#5
0
// CheckHealth runs the service's health command, returning the results
func (s *Service) CheckHealth() (int, error) {

	defer func() {
		// reset command object because it can't be reused
		if s.healthCheckCmd != nil {
			s.healthCheckCmd = utils.ArgsToCmd(s.healthCheckCmd.Args)
		}
	}()

	// if we have a valid Service but there's no health check
	// set, assume it always passes (ex. telemetry service).
	if s.healthCheckCmd == nil {
		return 0, nil
	}
	exitCode, err := utils.RunWithFields(s.healthCheckCmd, log.Fields{"process": "health", "serviceName": s.Name, "serviceID": s.ID})
	return exitCode, err
}
示例#6
0
func parseCoprocess(coprocess *Coprocess) error {
	args, err := utils.ToStringArray(coprocess.Command)
	if err != nil {
		return err
	}
	coprocess.Args = args
	if coprocess.Args == nil || len(coprocess.Args) == 0 {
		return fmt.Errorf("Coprocess did not provide a command")
	}
	cmd := utils.ArgsToCmd(coprocess.Args)
	coprocess.cmd = cmd

	if coprocess.Name == "" {
		coprocess.Name = strings.Join(coprocess.Args, " ")
	}

	return parseCoprocessRestarts(coprocess)
}
示例#7
0
// 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)
}