Browse code

Perform graceful shutdown during plugin disable.

Signed-off-by: Anusha Ragunathan <anusha@docker.com>

Anusha Ragunathan authored on 2016/11/15 08:07:21
Showing 1 changed files
... ...
@@ -9,6 +9,7 @@ import (
9 9
 	"time"
10 10
 
11 11
 	"github.com/Sirupsen/logrus"
12
+	"github.com/docker/docker/libcontainerd"
12 13
 	"github.com/docker/docker/oci"
13 14
 	"github.com/docker/docker/pkg/plugins"
14 15
 	"github.com/docker/docker/plugin/v2"
... ...
@@ -48,6 +49,25 @@ func (pm *Manager) restore(p *v2.Plugin) error {
48 48
 	return pm.containerdClient.Restore(p.GetID(), attachToLog(p.GetID()))
49 49
 }
50 50
 
51
+func shutdownPlugin(p *v2.Plugin, containerdClient libcontainerd.Client) {
52
+	pluginID := p.GetID()
53
+
54
+	err := containerdClient.Signal(pluginID, int(syscall.SIGTERM))
55
+	if err != nil {
56
+		logrus.Errorf("Sending SIGTERM to plugin failed with error: %v", err)
57
+	} else {
58
+		select {
59
+		case <-p.ExitChan:
60
+			logrus.Debug("Clean shutdown of plugin")
61
+		case <-time.After(time.Second * 10):
62
+			logrus.Debug("Force shutdown plugin")
63
+			if err := containerdClient.Signal(pluginID, int(syscall.SIGKILL)); err != nil {
64
+				logrus.Errorf("Sending SIGKILL to plugin failed with error: %v", err)
65
+			}
66
+		}
67
+	}
68
+}
69
+
51 70
 func (pm *Manager) disable(p *v2.Plugin) error {
52 71
 	if !p.IsEnabled() {
53 72
 		return fmt.Errorf("plugin %s is already disabled", p.Name())
... ...
@@ -55,9 +75,8 @@ func (pm *Manager) disable(p *v2.Plugin) error {
55 55
 	p.Lock()
56 56
 	p.Restart = false
57 57
 	p.Unlock()
58
-	if err := pm.containerdClient.Signal(p.GetID(), int(syscall.SIGKILL)); err != nil {
59
-		logrus.Error(err)
60
-	}
58
+
59
+	shutdownPlugin(p, pm.containerdClient)
61 60
 	pm.pluginStore.SetState(p, false)
62 61
 	return nil
63 62
 }
... ...
@@ -71,25 +90,11 @@ func (pm *Manager) Shutdown() {
71 71
 			continue
72 72
 		}
73 73
 		if pm.containerdClient != nil && p.IsEnabled() {
74
-			pluginID := p.GetID()
75 74
 			p.Lock()
76 75
 			p.ExitChan = make(chan bool)
77 76
 			p.Restart = false
78 77
 			p.Unlock()
79
-			err := pm.containerdClient.Signal(p.PluginObj.ID, int(syscall.SIGTERM))
80
-			if err != nil {
81
-				logrus.Errorf("Sending SIGTERM to plugin failed with error: %v", err)
82
-			} else {
83
-				select {
84
-				case <-p.ExitChan:
85
-					logrus.Debug("Clean shutdown of plugin")
86
-				case <-time.After(time.Second * 10):
87
-					logrus.Debug("Force shutdown plugin")
88
-					if err := pm.containerdClient.Signal(pluginID, int(syscall.SIGKILL)); err != nil {
89
-						logrus.Errorf("Sending SIGKILL to plugin failed with error: %v", err)
90
-					}
91
-				}
92
-			}
78
+			shutdownPlugin(p, pm.containerdClient)
93 79
 		}
94 80
 	}
95 81
 }