...
|
...
|
@@ -550,9 +550,21 @@ func (container *Container) kill() error {
|
550
|
550
|
if !container.State.Running || container.cmd == nil {
|
551
|
551
|
return nil
|
552
|
552
|
}
|
553
|
|
- if err := container.cmd.Process.Kill(); err != nil {
|
554
|
|
- return err
|
|
553
|
+
|
|
554
|
+ // Sending SIGINT to the process via lxc
|
|
555
|
+ output, err := exec.Command("lxc-kill", "-n", container.Id, "9").CombinedOutput()
|
|
556
|
+ if err != nil {
|
|
557
|
+ Debugf("error killing container %s (%s, %s)", container.Id, output, err)
|
555
|
558
|
}
|
|
559
|
+
|
|
560
|
+ // 2. Wait for the process to die, in last resort, try to kill the process directly
|
|
561
|
+ if err := container.WaitTimeout(10 * time.Second); err != nil {
|
|
562
|
+ log.Printf("Container %s failed to exit within 10 seconds of SIGINT - trying direct SIGKILL", container.Id)
|
|
563
|
+ if err := container.cmd.Process.Kill(); err != nil {
|
|
564
|
+ return err
|
|
565
|
+ }
|
|
566
|
+ }
|
|
567
|
+
|
556
|
568
|
// Wait for the container to be actually stopped
|
557
|
569
|
container.Wait()
|
558
|
570
|
return nil
|