Ensure a reliable way to kill ghost containers on reboot

Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
Michael Crosby
2014-04-01 07:11:41 +00:00
parent 5b9069bd99
commit 5bb82f6313
7 changed files with 83 additions and 9 deletions
+33 -3
View File
@@ -117,9 +117,39 @@ func (d *driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, startCallba
}
func (d *driver) Kill(p *execdriver.Command, sig int) error {
err := syscall.Kill(p.Process.Pid, syscall.Signal(sig))
return syscall.Kill(p.Process.Pid, syscall.Signal(sig))
}
func (d *driver) Terminate(p *execdriver.Command) error {
// lets check the start time for the process
started, err := d.readStartTime(p)
if err != nil {
// if we don't have the data on disk then we can assume the process is gone
// because this is only removed after we know the process has stopped
if os.IsNotExist(err) {
return nil
}
return err
}
currentStartTime, err := system.GetProcessStartTime(p.Process.Pid)
if err != nil {
return err
}
if started == currentStartTime {
err = syscall.Kill(p.Process.Pid, 9)
}
d.removeContainerRoot(p.ID)
return err
}
func (d *driver) readStartTime(p *execdriver.Command) (string, error) {
data, err := ioutil.ReadFile(filepath.Join(d.root, p.ID, "start"))
if err != nil {
return "", err
}
return string(data), nil
}
func (d *driver) Info(id string) execdriver.Info {
@@ -235,9 +265,9 @@ type dockerStateWriter struct {
callback execdriver.StartCallback
}
func (d *dockerStateWriter) WritePid(pid int) error {
func (d *dockerStateWriter) WritePid(pid int, started string) error {
d.c.ContainerPid = pid
err := d.dsw.WritePid(pid)
err := d.dsw.WritePid(pid, started)
if d.callback != nil {
d.callback(d.c)
}