Remove restartmanager from plugins

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi 2016-10-05 14:02:47 -07:00
Родитель 606a245d85
Коммит a452d1fccb
4 изменённых файлов: 33 добавлений и 54 удалений

Просмотреть файл

@ -32,14 +32,12 @@ type eventLogger func(id, name, action string)
// Manager controls the plugin subsystem. // Manager controls the plugin subsystem.
type Manager struct { type Manager struct {
sync.RWMutex
libRoot string libRoot string
runRoot string runRoot string
pluginStore *store.Store pluginStore *store.Store
containerdClient libcontainerd.Client containerdClient libcontainerd.Client
registryService registry.Service registryService registry.Service
liveRestore bool liveRestore bool
shutdown bool
pluginEventLogger eventLogger pluginEventLogger eventLogger
} }
@ -83,17 +81,20 @@ func (pm *Manager) StateChanged(id string, e libcontainerd.StateInfo) error {
switch e.State { switch e.State {
case libcontainerd.StateExit: case libcontainerd.StateExit:
var shutdown bool p, err := pm.pluginStore.GetByID(id)
pm.RLock() if err != nil {
shutdown = pm.shutdown return err
pm.RUnlock() }
if shutdown { p.RLock()
p, err := pm.pluginStore.GetByID(id) if p.ExitChan != nil {
if err != nil {
return err
}
close(p.ExitChan) close(p.ExitChan)
} }
restart := p.Restart
p.RUnlock()
p.RemoveFromDisk()
if restart {
pm.enable(p, true)
}
} }
return nil return nil

Просмотреть файл

@ -9,12 +9,9 @@ import (
"time" "time"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/libcontainerd"
"github.com/docker/docker/oci" "github.com/docker/docker/oci"
"github.com/docker/docker/pkg/plugins" "github.com/docker/docker/pkg/plugins"
"github.com/docker/docker/plugin/v2" "github.com/docker/docker/plugin/v2"
"github.com/docker/docker/restartmanager"
"github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-spec/specs-go"
) )
@ -26,20 +23,18 @@ func (pm *Manager) enable(p *v2.Plugin, force bool) error {
if err != nil { if err != nil {
return err return err
} }
p.Lock()
p.RestartManager = restartmanager.New(container.RestartPolicy{Name: "always"}, 0) p.Restart = true
if err := pm.containerdClient.Create(p.GetID(), "", "", specs.Spec(*spec), libcontainerd.WithRestartManager(p.RestartManager)); err != nil { p.Unlock()
if err := p.RestartManager.Cancel(); err != nil { if err := pm.containerdClient.Create(p.GetID(), "", "", specs.Spec(*spec)); err != nil {
logrus.Errorf("enable: restartManager.Cancel failed due to %v", err)
}
return err return err
} }
p.PClient, err = plugins.NewClient("unix://"+filepath.Join(p.RuntimeSourcePath, p.GetSocket()), nil) p.PClient, err = plugins.NewClient("unix://"+filepath.Join(p.RuntimeSourcePath, p.GetSocket()), nil)
if err != nil { if err != nil {
if err := p.RestartManager.Cancel(); err != nil { p.Lock()
logrus.Errorf("enable: restartManager.Cancel failed due to %v", err) p.Restart = false
} p.Unlock()
return err return err
} }
@ -50,49 +45,37 @@ func (pm *Manager) enable(p *v2.Plugin, force bool) error {
} }
func (pm *Manager) restore(p *v2.Plugin) error { func (pm *Manager) restore(p *v2.Plugin) error {
p.RestartManager = restartmanager.New(container.RestartPolicy{Name: "always"}, 0) return pm.containerdClient.Restore(p.GetID())
return pm.containerdClient.Restore(p.GetID(), libcontainerd.WithRestartManager(p.RestartManager))
} }
func (pm *Manager) disable(p *v2.Plugin) error { func (pm *Manager) disable(p *v2.Plugin) error {
if !p.IsEnabled() { if !p.IsEnabled() {
return fmt.Errorf("plugin %s is already disabled", p.Name()) return fmt.Errorf("plugin %s is already disabled", p.Name())
} }
if err := p.RestartManager.Cancel(); err != nil { p.Lock()
logrus.Error(err) p.Restart = false
} p.Unlock()
if err := pm.containerdClient.Signal(p.GetID(), int(syscall.SIGKILL)); err != nil { if err := pm.containerdClient.Signal(p.GetID(), int(syscall.SIGKILL)); err != nil {
logrus.Error(err) logrus.Error(err)
} }
if err := p.RemoveFromDisk(); err != nil {
logrus.Error(err)
}
pm.pluginStore.SetState(p, false) pm.pluginStore.SetState(p, false)
return nil return nil
} }
// Shutdown stops all plugins and called during daemon shutdown. // Shutdown stops all plugins and called during daemon shutdown.
func (pm *Manager) Shutdown() { func (pm *Manager) Shutdown() {
pm.Lock()
pm.shutdown = true
pm.Unlock()
pm.RLock()
defer pm.RUnlock()
plugins := pm.pluginStore.GetAll() plugins := pm.pluginStore.GetAll()
for _, p := range plugins { for _, p := range plugins {
if pm.liveRestore && p.IsEnabled() { if pm.liveRestore && p.IsEnabled() {
logrus.Debug("Plugin active when liveRestore is set, skipping shutdown") logrus.Debug("Plugin active when liveRestore is set, skipping shutdown")
continue continue
} }
if p.RestartManager != nil {
if err := p.RestartManager.Cancel(); err != nil {
logrus.Error(err)
}
}
if pm.containerdClient != nil && p.IsEnabled() { if pm.containerdClient != nil && p.IsEnabled() {
pluginID := p.GetID() pluginID := p.GetID()
p.Lock()
p.ExitChan = make(chan bool) p.ExitChan = make(chan bool)
p.Restart = false
p.Unlock()
err := pm.containerdClient.Signal(p.PluginObj.ID, int(syscall.SIGTERM)) err := pm.containerdClient.Signal(p.PluginObj.ID, int(syscall.SIGTERM))
if err != nil { if err != nil {
logrus.Errorf("Sending SIGTERM to plugin failed with error: %v", err) logrus.Errorf("Sending SIGTERM to plugin failed with error: %v", err)
@ -108,8 +91,5 @@ func (pm *Manager) Shutdown() {
} }
} }
} }
if err := p.RemoveFromDisk(); err != nil {
logrus.Errorf("Remove plugin runtime failed with error: %v", err)
}
} }
} }

Просмотреть файл

@ -111,13 +111,12 @@ func (ps *Store) Add(p *v2.Plugin) {
ps.Unlock() ps.Unlock()
} }
// Remove removes a plugin from memory, plugindb and disk. // Remove removes a plugin from memory and plugindb.
func (ps *Store) Remove(p *v2.Plugin) { func (ps *Store) Remove(p *v2.Plugin) {
ps.Lock() ps.Lock()
delete(ps.plugins, p.GetID()) delete(ps.plugins, p.GetID())
delete(ps.nameToID, p.Name()) delete(ps.nameToID, p.Name())
ps.updatePluginDB() ps.updatePluginDB()
p.RemoveFromDisk()
ps.Unlock() ps.Unlock()
} }

Просмотреть файл

@ -5,16 +5,15 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/plugins" "github.com/docker/docker/pkg/plugins"
"github.com/docker/docker/restartmanager"
) )
// Plugin represents an individual plugin. // Plugin represents an individual plugin.
type Plugin struct { type Plugin struct {
sync.RWMutex sync.RWMutex
PluginObj types.Plugin `json:"plugin"` PluginObj types.Plugin `json:"plugin"`
PClient *plugins.Client `json:"-"` PClient *plugins.Client `json:"-"`
RestartManager restartmanager.RestartManager `json:"-"` RuntimeSourcePath string `json:"-"`
RuntimeSourcePath string `json:"-"` RefCount int `json:"-"`
ExitChan chan bool `json:"-"` Restart bool `json:"-"`
RefCount int `json:"-"` ExitChan chan bool `json:"-"`
} }