cplugind

package
v1.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2025 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FlagCraneConfig string
	FlagDebugLevel  string
)
View Source
var RootCmd = &cobra.Command{
	Use:     "cplugind",
	Short:   "cplugind is a plugin daemon for CraneSched",
	Args:    cobra.ExactArgs(0),
	Version: util.Version(),
	Run: func(cmd *cobra.Command, args []string) {

		util.DetectNetworkProxy()

		config := util.ParseConfig(FlagCraneConfig)
		if config == nil {
			log.Errorf("Failed to parse CraneSched config")
			os.Exit(util.ErrorCmdArg)
		}

		if err := ParsePluginConfig(config.CraneBaseDir, FlagCraneConfig); err != nil {
			log.Errorf("Failed to parse the plugin part in config: %v", err)
			os.Exit(util.ErrorCmdArg)
		}

		if !gPluginConfig.Enabled {
			log.Errorf("Plugind is disabled in config.")
			os.Exit(util.ErrorCmdArg)
		}

		if cmd.Flags().Changed("debug-level") {
			util.InitLogger(FlagDebugLevel)
		} else {
			util.InitLogger(gPluginConfig.LogLevel)
		}

		log.Info("Loading plugins...")
		if err := LoadPluginsByConfig(gPluginConfig.Plugins); err != nil {
			log.Errorf("Failed to load plugins: %v", err)
			os.Exit(util.ErrorCmdArg)
		}

		log.Info("Initializing plugins...")
		for _, p := range gPluginMap {
			if err := (*p).Load(p.Meta); err != nil {
				log.Errorf("Failed to init plugin: %v", err)
				os.Exit(util.ErrorGeneric)
			}
		}

		pd := NewPluginD(nil)

		unixSocket, err := util.GetUnixSocket(gPluginConfig.SockPath, 0600)
		if err != nil {
			log.Errorf("Failed to get UNIX socket: %v", err)
			os.Exit(util.ErrorGeneric)
		}

		log.Infof("gRPC server listening on %s.", gPluginConfig.SockPath)
		if err := pd.Launch(unixSocket); err != nil {
			log.Errorf("Failed to launch plugin daemon: %v", err)
			os.Exit(util.ErrorGeneric)
		}

		sigs := make(chan os.Signal, 1)
		signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

		sig := <-sigs
		switch sig {
		case syscall.SIGINT:
			log.Infof("Received SIGINT, exiting...")
			pd.GracefulStop()
		case syscall.SIGTERM:
			log.Infof("Received SIGTERM, exiting...")
			pd.Stop()
		}

		if err := UnloadPlugins(); err != nil {
			log.Errorf("Failed to unload plugins: %v", err)
			os.Exit(util.ErrorGeneric)
		}
	},
}

Functions

func LoadPluginsByConfig

func LoadPluginsByConfig(pl []api.PluginMeta) error

func ParseCmdArgs

func ParseCmdArgs()

func ParsePluginConfig

func ParsePluginConfig(basedir string, path string) error

func UnloadPlugins

func UnloadPlugins() error

Types

type PluginDaemon

type PluginDaemon struct {
	protos.UnimplementedCranePluginDServer
	Server *grpc.Server
}

func NewPluginD

func NewPluginD(opts []grpc.ServerOption) *PluginDaemon

func (*PluginDaemon) CreateCgroupHook

func (*PluginDaemon) DestroyCgroupHook

func (*PluginDaemon) EndHook

func (*PluginDaemon) GracefulStop

func (pd *PluginDaemon) GracefulStop()

func (*PluginDaemon) Launch

func (pd *PluginDaemon) Launch(socket net.Listener) error

func (*PluginDaemon) StartHook

func (*PluginDaemon) Stop

func (pd *PluginDaemon) Stop()

type PluginLoaded

type PluginLoaded struct {
	api.Plugin

	Meta api.PluginMeta
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL