コード例 #1
0
ファイル: beat.go プロジェクト: radoondas/apachebeat
// launch manages the lifecycle of the beat and guarantees the order in which
// the Beater methods are invokes and ensures a a proper exit code is set when
// an error occurs. The exit flag controls if this method calls os.Exit when
// it completes.
func (bc *instance) launch(exit bool) error {
	var err error
	if exit {
		defer func() { exitProcess(err) }()
	}

	err = bc.handleFlags()
	if err != nil {
		return err
	}

	err = bc.config()
	if err != nil {
		return err
	}

	defer bc.cleanup()
	err = bc.setup()
	if err != nil {
		return err
	}

	svc.BeforeRun()
	svc.HandleSignals(bc.beater.Stop)
	err = bc.run()
	return err
}
コード例 #2
0
ファイル: beat.go プロジェクト: cleesmith/unifiedbeat
// Run calls the beater Setup and Run methods. In case of errors
// during the setup phase, it exits the process.
func (b *Beat) Run() error {

	// Setup beater object
	err := b.BT.Setup(b)
	if err != nil {
		return fmt.Errorf("setup returned an error: %v", err)
	}
	b.setState(SetupState)

	// Up to here was the initialization, now about running
	if cfgfile.IsTestConfig() {
		logp.Info("Testing configuration file")
		// all good, exit
		return nil
	}
	service.BeforeRun()

	// Callback is called if the processes is asked to stop.
	// This needs to be called before the main loop is started so that
	// it can register the signals that stop or query (on Windows) the loop.
	service.HandleSignals(b.Exit)

	logp.Info("%s sucessfully setup. Start running.", b.Name)

	b.setState(RunState)
	// Run beater specific stuff
	err = b.BT.Run(b)
	if err != nil {
		logp.Critical("Running the beat returned an error: %v", err)
	}

	return err
}
コード例 #3
0
ファイル: beat.go プロジェクト: ChongFeng/beats
func (b *Beat) launch(bt Creator) error {
	err := b.handleFlags()
	if err != nil {
		return err
	}

	svc.BeforeRun()
	defer svc.Cleanup()

	if err := b.configure(); err != nil {
		return err
	}

	// load the beats config section
	var sub *common.Config
	configName := strings.ToLower(b.Name)
	if b.RawConfig.HasField(configName) {
		sub, err = b.RawConfig.Child(configName, -1)
		if err != nil {
			return err
		}
	} else {
		sub = common.NewConfig()
	}

	logp.Info("Setup Beat: %s; Version: %s", b.Name, b.Version)
	processors, err := processors.New(b.Config.Processors)
	if err != nil {
		return fmt.Errorf("error initializing processors: %v", err)
	}

	debugf("Initializing output plugins")
	publisher, err := publisher.New(b.Name, b.Config.Output, b.Config.Shipper, processors)
	if err != nil {
		return fmt.Errorf("error initializing publisher: %v", err)
	}

	// TODO: some beats race on shutdown with publisher.Stop -> do not call Stop yet,
	//       but refine publisher to disconnect clients on stop automatically
	// defer publisher.Stop()

	b.Publisher = publisher
	beater, err := bt(b, sub)
	if err != nil {
		return err
	}

	// If -configtest was specified, exit now prior to run.
	if cfgfile.IsTestConfig() {
		fmt.Println("Config OK")
		return GracefulExit
	}

	svc.HandleSignals(beater.Stop)

	logp.Info("%s start running.", b.Name)
	defer logp.Info("%s stopped.", b.Name)

	return beater.Run(b)
}
コード例 #4
0
ファイル: beat.go プロジェクト: QunarBlackOps/beats
// Run calls the beater Setup and Run methods. In case of errors
// during the setup phase, it exits the process.
func (b *Beat) Run() error {

	// Setup beater object
	err := b.BT.Setup(b)
	if err != nil {
		logp.Critical("Setup returned an error: %v", err)
		os.Exit(1)
	}

	// Up to here was the initialization, now about running
	if cfgfile.IsTestConfig() {
		// all good, exit with 0
		os.Exit(0)
	}
	service.BeforeRun()

	// Callback is called if the processes is asked to stop.
	// This needs to be called before the main loop is started so that
	// it can register the signals that stop or query (on Windows) the loop.
	service.HandleSignals(b.Exit)

	logp.Info("%s sucessfully setup. Start running.", b.Name)

	// Run beater specific stuff
	err = b.BT.Run(b)
	if err != nil {
		logp.Critical("Running the beat returned an error: %v", err)
	}

	service.Cleanup()

	logp.Info("Cleaning up %s before shutting down.", b.Name)

	// Call beater cleanup function
	err = b.BT.Cleanup(b)
	if err != nil {
		logp.Err("Cleanup returned an error: %v", err)
	}
	return err
}
コード例 #5
0
ファイル: beat.go プロジェクト: yan2jared/beats
// launch manages the lifecycle of the beat and guarantees the order in which
// the Beater methods are invoked. If an error occurs in the lifecycle of the
// Beat it will be returned.
func (bc *instance) launch() (err error) {
	defer func() { err = handleError(err) }()

	err = bc.handleFlags()
	if err != nil {
		return
	}

	err = bc.config()
	if err != nil {
		return
	}

	defer bc.cleanup()
	err = bc.setup()
	if err != nil {
		return
	}

	svc.BeforeRun()
	svc.HandleSignals(bc.beater.Stop)
	err = bc.run()
	return
}