func (pm *Manager) enable(p *v2.Plugin, force bool) error { if p.IsEnabled() && !force { return fmt.Errorf("plugin %s is already enabled", p.Name()) } spec, err := p.InitSpec(oci.DefaultSpec(), pm.libRoot) if err != nil { return err } p.RestartManager = restartmanager.New(container.RestartPolicy{Name: "always"}, 0) if err := pm.containerdClient.Create(p.GetID(), "", "", specs.Spec(*spec), libcontainerd.WithRestartManager(p.RestartManager)); err != nil { if err := p.RestartManager.Cancel(); err != nil { logrus.Errorf("enable: restartManager.Cancel failed due to %v", err) } return err } p.PClient, err = plugins.NewClient("unix://"+filepath.Join(p.RuntimeSourcePath, p.GetSocket()), nil) if err != nil { if err := p.RestartManager.Cancel(); err != nil { logrus.Errorf("enable: restartManager.Cancel failed due to %v", err) } return err } pm.pluginStore.SetState(p, true) pm.pluginStore.CallHandler(p) return nil }
func (pm *Manager) enable(p *v2.Plugin, force bool) error { if p.IsEnabled() && !force { return fmt.Errorf("plugin %s is already enabled", p.Name()) } spec, err := p.InitSpec(oci.DefaultSpec(), pm.libRoot) if err != nil { return err } p.Lock() p.Restart = true p.Unlock() if err := pm.containerdClient.Create(p.GetID(), "", "", specs.Spec(*spec)); err != nil { return err } p.PClient, err = plugins.NewClient("unix://"+filepath.Join(p.RuntimeSourcePath, p.GetSocket()), nil) if err != nil { p.Lock() p.Restart = false p.Unlock() return err } pm.pluginStore.SetState(p, true) pm.pluginStore.CallHandler(p) return nil }
func (pm *Manager) enable(p *v2.Plugin, c *controller, force bool) error { if p.IsEnabled() && !force { return fmt.Errorf("plugin %s is already enabled", p.Name()) } spec, err := p.InitSpec(oci.DefaultSpec(), pm.libRoot) if err != nil { return err } c.restart = true c.exitChan = make(chan bool) pm.mu.Lock() pm.cMap[p] = c pm.mu.Unlock() if err := pm.containerdClient.Create(p.GetID(), "", "", specs.Spec(*spec), attachToLog(p.GetID())); err != nil { return err } client, err := plugins.NewClientWithTimeout("unix://"+filepath.Join(p.GetRuntimeSourcePath(), p.GetSocket()), nil, c.timeoutInSecs) if err != nil { c.restart = false shutdownPlugin(p, c, pm.containerdClient) return err } p.SetPClient(client) pm.pluginStore.SetState(p, true) pm.pluginStore.CallHandler(p) return nil }
func (pm *Manager) pluginPostStart(p *v2.Plugin, c *controller) error { client, err := plugins.NewClientWithTimeout("unix://"+filepath.Join(pm.config.ExecRoot, p.GetID(), p.GetSocket()), nil, c.timeoutInSecs) if err != nil { c.restart = false shutdownPlugin(p, c, pm.containerdClient) return err } p.SetPClient(client) pm.config.Store.SetState(p, true) pm.config.Store.CallHandler(p) return pm.save(p) }