From 46c83a02af18b7c56b35983c698015a2efa82eff Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Thu, 11 Apr 2013 09:02:34 -0700 Subject: [PATCH] force kill now use lxc-kill. Fixes #383 Upstream-commit: e68c04b722b4c001c999abc2cd5b60b1f1b34457 Component: engine --- components/engine/container.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/components/engine/container.go b/components/engine/container.go index f180c7559b..06f39083d8 100644 --- a/components/engine/container.go +++ b/components/engine/container.go @@ -550,9 +550,21 @@ func (container *Container) kill() error { if !container.State.Running || container.cmd == nil { return nil } - if err := container.cmd.Process.Kill(); err != nil { - return err + + // Sending SIGINT to the process via lxc + output, err := exec.Command("lxc-kill", "-n", container.Id, "9").CombinedOutput() + if err != nil { + Debugf("error killing container %s (%s, %s)", container.Id, output, err) } + + // 2. Wait for the process to die, in last resort, try to kill the process directly + if err := container.WaitTimeout(10 * time.Second); err != nil { + log.Printf("Container %s failed to exit within 10 seconds of SIGINT - trying direct SIGKILL", container.Id) + if err := container.cmd.Process.Kill(); err != nil { + return err + } + } + // Wait for the container to be actually stopped container.Wait() return nil