Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
| ... | ... |
@@ -32,14 +32,12 @@ type eventLogger func(id, name, action string) |
| 32 | 32 |
|
| 33 | 33 |
// Manager controls the plugin subsystem. |
| 34 | 34 |
type Manager struct {
|
| 35 |
- sync.RWMutex |
|
| 36 | 35 |
libRoot string |
| 37 | 36 |
runRoot string |
| 38 | 37 |
pluginStore *store.Store |
| 39 | 38 |
containerdClient libcontainerd.Client |
| 40 | 39 |
registryService registry.Service |
| 41 | 40 |
liveRestore bool |
| 42 |
- shutdown bool |
|
| 43 | 41 |
pluginEventLogger eventLogger |
| 44 | 42 |
} |
| 45 | 43 |
|
| ... | ... |
@@ -83,17 +81,20 @@ func (pm *Manager) StateChanged(id string, e libcontainerd.StateInfo) error {
|
| 83 | 83 |
|
| 84 | 84 |
switch e.State {
|
| 85 | 85 |
case libcontainerd.StateExit: |
| 86 |
- var shutdown bool |
|
| 87 |
- pm.RLock() |
|
| 88 |
- shutdown = pm.shutdown |
|
| 89 |
- pm.RUnlock() |
|
| 90 |
- if shutdown {
|
|
| 91 |
- p, err := pm.pluginStore.GetByID(id) |
|
| 92 |
- if err != nil {
|
|
| 93 |
- return err |
|
| 94 |
- } |
|
| 86 |
+ p, err := pm.pluginStore.GetByID(id) |
|
| 87 |
+ if err != nil {
|
|
| 88 |
+ return err |
|
| 89 |
+ } |
|
| 90 |
+ p.RLock() |
|
| 91 |
+ if p.ExitChan != nil {
|
|
| 95 | 92 |
close(p.ExitChan) |
| 96 | 93 |
} |
| 94 |
+ restart := p.Restart |
|
| 95 |
+ p.RUnlock() |
|
| 96 |
+ p.RemoveFromDisk() |
|
| 97 |
+ if restart {
|
|
| 98 |
+ pm.enable(p, true) |
|
| 99 |
+ } |
|
| 97 | 100 |
} |
| 98 | 101 |
|
| 99 | 102 |
return nil |
| ... | ... |
@@ -9,12 +9,9 @@ import ( |
| 9 | 9 |
"time" |
| 10 | 10 |
|
| 11 | 11 |
"github.com/Sirupsen/logrus" |
| 12 |
- "github.com/docker/docker/api/types/container" |
|
| 13 |
- "github.com/docker/docker/libcontainerd" |
|
| 14 | 12 |
"github.com/docker/docker/oci" |
| 15 | 13 |
"github.com/docker/docker/pkg/plugins" |
| 16 | 14 |
"github.com/docker/docker/plugin/v2" |
| 17 |
- "github.com/docker/docker/restartmanager" |
|
| 18 | 15 |
"github.com/opencontainers/runtime-spec/specs-go" |
| 19 | 16 |
) |
| 20 | 17 |
|
| ... | ... |
@@ -26,20 +23,18 @@ func (pm *Manager) enable(p *v2.Plugin, force bool) error {
|
| 26 | 26 |
if err != nil {
|
| 27 | 27 |
return err |
| 28 | 28 |
} |
| 29 |
- |
|
| 30 |
- p.RestartManager = restartmanager.New(container.RestartPolicy{Name: "always"}, 0)
|
|
| 31 |
- if err := pm.containerdClient.Create(p.GetID(), "", "", specs.Spec(*spec), libcontainerd.WithRestartManager(p.RestartManager)); err != nil {
|
|
| 32 |
- if err := p.RestartManager.Cancel(); err != nil {
|
|
| 33 |
- logrus.Errorf("enable: restartManager.Cancel failed due to %v", err)
|
|
| 34 |
- } |
|
| 29 |
+ p.Lock() |
|
| 30 |
+ p.Restart = true |
|
| 31 |
+ p.Unlock() |
|
| 32 |
+ if err := pm.containerdClient.Create(p.GetID(), "", "", specs.Spec(*spec)); err != nil {
|
|
| 35 | 33 |
return err |
| 36 | 34 |
} |
| 37 | 35 |
|
| 38 | 36 |
p.PClient, err = plugins.NewClient("unix://"+filepath.Join(p.RuntimeSourcePath, p.GetSocket()), nil)
|
| 39 | 37 |
if err != nil {
|
| 40 |
- if err := p.RestartManager.Cancel(); err != nil {
|
|
| 41 |
- logrus.Errorf("enable: restartManager.Cancel failed due to %v", err)
|
|
| 42 |
- } |
|
| 38 |
+ p.Lock() |
|
| 39 |
+ p.Restart = false |
|
| 40 |
+ p.Unlock() |
|
| 43 | 41 |
return err |
| 44 | 42 |
} |
| 45 | 43 |
|
| ... | ... |
@@ -50,49 +45,37 @@ func (pm *Manager) enable(p *v2.Plugin, force bool) error {
|
| 50 | 50 |
} |
| 51 | 51 |
|
| 52 | 52 |
func (pm *Manager) restore(p *v2.Plugin) error {
|
| 53 |
- p.RestartManager = restartmanager.New(container.RestartPolicy{Name: "always"}, 0)
|
|
| 54 |
- return pm.containerdClient.Restore(p.GetID(), libcontainerd.WithRestartManager(p.RestartManager)) |
|
| 53 |
+ return pm.containerdClient.Restore(p.GetID()) |
|
| 55 | 54 |
} |
| 56 | 55 |
|
| 57 | 56 |
func (pm *Manager) disable(p *v2.Plugin) error {
|
| 58 | 57 |
if !p.IsEnabled() {
|
| 59 | 58 |
return fmt.Errorf("plugin %s is already disabled", p.Name())
|
| 60 | 59 |
} |
| 61 |
- if err := p.RestartManager.Cancel(); err != nil {
|
|
| 62 |
- logrus.Error(err) |
|
| 63 |
- } |
|
| 60 |
+ p.Lock() |
|
| 61 |
+ p.Restart = false |
|
| 62 |
+ p.Unlock() |
|
| 64 | 63 |
if err := pm.containerdClient.Signal(p.GetID(), int(syscall.SIGKILL)); err != nil {
|
| 65 | 64 |
logrus.Error(err) |
| 66 | 65 |
} |
| 67 |
- if err := p.RemoveFromDisk(); err != nil {
|
|
| 68 |
- logrus.Error(err) |
|
| 69 |
- } |
|
| 70 | 66 |
pm.pluginStore.SetState(p, false) |
| 71 | 67 |
return nil |
| 72 | 68 |
} |
| 73 | 69 |
|
| 74 | 70 |
// Shutdown stops all plugins and called during daemon shutdown. |
| 75 | 71 |
func (pm *Manager) Shutdown() {
|
| 76 |
- pm.Lock() |
|
| 77 |
- pm.shutdown = true |
|
| 78 |
- pm.Unlock() |
|
| 79 |
- |
|
| 80 |
- pm.RLock() |
|
| 81 |
- defer pm.RUnlock() |
|
| 82 | 72 |
plugins := pm.pluginStore.GetAll() |
| 83 | 73 |
for _, p := range plugins {
|
| 84 | 74 |
if pm.liveRestore && p.IsEnabled() {
|
| 85 | 75 |
logrus.Debug("Plugin active when liveRestore is set, skipping shutdown")
|
| 86 | 76 |
continue |
| 87 | 77 |
} |
| 88 |
- if p.RestartManager != nil {
|
|
| 89 |
- if err := p.RestartManager.Cancel(); err != nil {
|
|
| 90 |
- logrus.Error(err) |
|
| 91 |
- } |
|
| 92 |
- } |
|
| 93 | 78 |
if pm.containerdClient != nil && p.IsEnabled() {
|
| 94 | 79 |
pluginID := p.GetID() |
| 80 |
+ p.Lock() |
|
| 95 | 81 |
p.ExitChan = make(chan bool) |
| 82 |
+ p.Restart = false |
|
| 83 |
+ p.Unlock() |
|
| 96 | 84 |
err := pm.containerdClient.Signal(p.PluginObj.ID, int(syscall.SIGTERM)) |
| 97 | 85 |
if err != nil {
|
| 98 | 86 |
logrus.Errorf("Sending SIGTERM to plugin failed with error: %v", err)
|
| ... | ... |
@@ -108,8 +91,5 @@ func (pm *Manager) Shutdown() {
|
| 108 | 108 |
} |
| 109 | 109 |
} |
| 110 | 110 |
} |
| 111 |
- if err := p.RemoveFromDisk(); err != nil {
|
|
| 112 |
- logrus.Errorf("Remove plugin runtime failed with error: %v", err)
|
|
| 113 |
- } |
|
| 114 | 111 |
} |
| 115 | 112 |
} |
| ... | ... |
@@ -111,13 +111,12 @@ func (ps *Store) Add(p *v2.Plugin) {
|
| 111 | 111 |
ps.Unlock() |
| 112 | 112 |
} |
| 113 | 113 |
|
| 114 |
-// Remove removes a plugin from memory, plugindb and disk. |
|
| 114 |
+// Remove removes a plugin from memory and plugindb. |
|
| 115 | 115 |
func (ps *Store) Remove(p *v2.Plugin) {
|
| 116 | 116 |
ps.Lock() |
| 117 | 117 |
delete(ps.plugins, p.GetID()) |
| 118 | 118 |
delete(ps.nameToID, p.Name()) |
| 119 | 119 |
ps.updatePluginDB() |
| 120 |
- p.RemoveFromDisk() |
|
| 121 | 120 |
ps.Unlock() |
| 122 | 121 |
} |
| 123 | 122 |
|
| ... | ... |
@@ -5,16 +5,15 @@ import ( |
| 5 | 5 |
|
| 6 | 6 |
"github.com/docker/docker/api/types" |
| 7 | 7 |
"github.com/docker/docker/pkg/plugins" |
| 8 |
- "github.com/docker/docker/restartmanager" |
|
| 9 | 8 |
) |
| 10 | 9 |
|
| 11 | 10 |
// Plugin represents an individual plugin. |
| 12 | 11 |
type Plugin struct {
|
| 13 | 12 |
sync.RWMutex |
| 14 |
- PluginObj types.Plugin `json:"plugin"` |
|
| 15 |
- PClient *plugins.Client `json:"-"` |
|
| 16 |
- RestartManager restartmanager.RestartManager `json:"-"` |
|
| 17 |
- RuntimeSourcePath string `json:"-"` |
|
| 18 |
- ExitChan chan bool `json:"-"` |
|
| 19 |
- RefCount int `json:"-"` |
|
| 13 |
+ PluginObj types.Plugin `json:"plugin"` |
|
| 14 |
+ PClient *plugins.Client `json:"-"` |
|
| 15 |
+ RuntimeSourcePath string `json:"-"` |
|
| 16 |
+ RefCount int `json:"-"` |
|
| 17 |
+ Restart bool `json:"-"` |
|
| 18 |
+ ExitChan chan bool `json:"-"` |
|
| 20 | 19 |
} |