Move kill-on-failure responsibility to caller of weave script

This commit is contained in:
Bryan Boreham committed 2016-05-16 13:38:22 +01:00
1 parent ef5f80a05a
commit ff81ecfd41
2 files changed
+32 -43

No files matched your search

+22 -12
View File
@@ -103,7 +103,7 @@ func (proxy *Proxy) attachWithRetry(id string) {
j := &attachJob{id: id, tryInterval: initialInterval}
j.timer = time.AfterFunc(time.Duration(0), func() {
if err := proxy.attach(id, false, false); err != nil {
if err := proxy.attach(id); err != nil {
// The delay at the nth retry is a random value in the range
// [i-i/2,i+i/2], where i = initialInterval * 1.5^(n-1).
j.timer.Reset(j.tryInterval)
@@ -383,9 +383,26 @@ func (proxy *Proxy) listen(protoAndAddr string) (net.Listener, string, error) {
// weavedocker.ContainerObserver interface
func (proxy *Proxy) ContainerStarted(ident string) {
// In case of attach failure, if we have a request waiting on the start, kill the container,
// otherwise assume it is a Docker-initated restart and kill the process inside.
err := proxy.attach(ident, true, proxy.waitChan(ident) == nil)
err := proxy.attach(ident)
if err != nil {
var e error
// attach failed: if we have a request waiting on the start, kill the container,
// otherwise assume it is a Docker-initated restart and kill the process inside.
if proxy.waitChan(ident) != nil {
e = proxy.client.KillContainer(docker.KillContainerOptions{ID: ident})
} else {
var c *docker.Container
if c, e = proxy.client.InspectContainer(ident); e == nil {
var process *os.Process
if process, e = os.FindProcess(c.State.Pid); e == nil {
e = process.Kill()
}
}
}
if e != nil {
Log.Warningf("Error killing %s: %s", ident, e)
}
}
proxy.notifyWaiters(ident, err)
}
@@ -466,7 +483,7 @@ func (proxy *Proxy) ContainerDestroyed(ident string) {}
// Check if this container needs to be attached, if so then attach it,
// and return nil on success or not needed.
func (proxy *Proxy) attach(containerID string, orDie, killProcess bool) error {
func (proxy *Proxy) attach(containerID string) error {
container, err := proxy.client.InspectContainer(containerID)
if err != nil {
if _, ok := err.(*docker.NoSuchContainer); !ok {
@@ -502,13 +519,6 @@ func (proxy *Proxy) attach(containerID string, orDie, killProcess bool) error {
if proxy.NoMulticastRoute {
args = append(args, "--no-multicast-route")
}
if orDie {
if killProcess {
args = append(args, "--or-kill")
} else {
args = append(args, "--or-die")
}
}
args = append(args, container.ID)
return callWeaveAttach(container, args)
}