func (r *ExecRunner) run() {
	log.Infof("[%s] Starting (%s driver)", r.name, r.backend.Driver())

	if r.stderr != "" {
		err := common.CreatePathToFile(r.stderr)
		if err != nil {
			backends.SetStatusLogErrorf(r.name, "Failed to create path to collector's stderr log: %s", r.stderr)
		}

		f := common.GetRotatedLog(r.stderr, r.context.UserConfig.LogRotationTime, r.context.UserConfig.LogMaxAge)
		defer f.Close()
		r.cmd.Stderr = f
	}
	if r.stdout != "" {
		err := common.CreatePathToFile(r.stdout)
		if err != nil {
			backends.SetStatusLogErrorf(r.name, "Failed to create path to collector's stdout log: %s", r.stdout)
		}

		f := common.GetRotatedLog(r.stderr, r.context.UserConfig.LogRotationTime, r.context.UserConfig.LogMaxAge)
		defer f.Close()
		r.cmd.Stdout = f
	}

	r.backend.SetStatus(backends.StatusRunning, "Running")
	err := r.cmd.Start()
	if err != nil {
		backends.SetStatusLogErrorf(r.name, "Failed to start collector: %s", err)
	}
}
Example #2
0
func (r *Runner) run() {
	log.Infof("[%s] Starting", r.Name)

	if r.Stderr != "" {
		err := common.CreatePathToFile(r.Stderr)
		if err != nil {
			msg := "Failed to create path to collector's stderr log"
			r.Backend.SetStatus(backends.StatusError, msg)
			log.Errorf("[%s] %s: %s", r.Name, msg, r.Stderr)
		}

		f := common.GetRotatedLog(r.Stderr, r.Context.UserConfig.LogRotationTime, r.Context.UserConfig.LogMaxAge)
		defer f.Close()
		r.cmd.Stderr = f
	}
	if r.Stdout != "" {
		err := common.CreatePathToFile(r.Stdout)
		if err != nil {
			msg := "Failed to create path to collector's stdout log"
			r.Backend.SetStatus(backends.StatusError, msg)
			log.Errorf("[%s] %s: %s", r.Name, msg, r.Stdout)
		}

		f := common.GetRotatedLog(r.Stderr, r.Context.UserConfig.LogRotationTime, r.Context.UserConfig.LogMaxAge)
		defer f.Close()
		r.cmd.Stdout = f
	}

	r.Running = true
	r.Backend.SetStatus(backends.StatusRunning, "Running")
	startTime := time.Now()
	r.cmd.Run()

	if time.Since(startTime) < 3*time.Second {
		msg := "Collector exits immediately, this should not happen! Please check your collector configuration!"
		r.Backend.SetStatus(backends.StatusError, msg)
		log.Errorf("[%s] %s", r.Name, msg)
	}

	return
}