Example #1
0
// registerPlugins makes plugins available for use by the agent.
func registerPlugins(registry plugin.Registry, plugins []plugin.CommandPlugin, logger *comm.StreamLogger) error {
	for _, pl := range plugins {
		if err := registry.Register(pl); err != nil {
			return fmt.Errorf("Failed to register plugin %v: %v", pl.Name(), err)
		}
		logger.LogExecution(slogger.INFO, "Registered plugin %v", pl.Name())
	}
	return nil
}
Example #2
0
// ExitAgent removes the pid file and exits the process with the given exit code.
func ExitAgent(logger *comm.StreamLogger, exitCode int, pidFile string) {
	err := os.Remove(pidFile)
	if err != nil {
		if logger != nil {
			logger.LogLocal(slogger.ERROR, "Error removing .pid file: %v", err)
			logger.Flush()
		} else {
			fmt.Printf("Error removing .pid file: %v", err)
		}
		// exit with code 2 to indicate pid file removal error
		os.Exit(2)
	}
	os.Exit(exitCode)
}