From 1716cbe80646029f86475eeef4674db206680fc6 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Wed, 26 Mar 2014 06:48:16 +0000 Subject: [PATCH 1/2] Ensure a reliable way to kill ghost containers on reboot Docker-DCO-1.1-Signed-off-by: Michael Crosby (github: crosbymichael) --- nsinit/exec.go | 7 ++++++- nsinit/state.go | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/nsinit/exec.go b/nsinit/exec.go index 73842f72..c07c45de 100644 --- a/nsinit/exec.go +++ b/nsinit/exec.go @@ -50,8 +50,13 @@ func (ns *linuxNs) Exec(container *libcontainer.Container, term Terminal, args [ if err := command.Start(); err != nil { return -1, err } + + started, err := system.GetProcessStartTime(command.Process.Pid) + if err != nil { + return -1, err + } ns.logger.Printf("writting pid %d to file\n", command.Process.Pid) - if err := ns.stateWriter.WritePid(command.Process.Pid); err != nil { + if err := ns.stateWriter.WritePid(command.Process.Pid, started); err != nil { command.Process.Kill() return -1, err } diff --git a/nsinit/state.go b/nsinit/state.go index af38008c..26d7fa42 100644 --- a/nsinit/state.go +++ b/nsinit/state.go @@ -10,7 +10,7 @@ import ( // StateWriter handles writing and deleting the pid file // on disk type StateWriter interface { - WritePid(pid int) error + WritePid(pid int, startTime string) error DeletePid() error } @@ -19,10 +19,18 @@ type DefaultStateWriter struct { } // writePidFile writes the namespaced processes pid to pid in the rootfs for the container -func (d *DefaultStateWriter) WritePid(pid int) error { - return ioutil.WriteFile(filepath.Join(d.Root, "pid"), []byte(fmt.Sprint(pid)), 0655) +func (d *DefaultStateWriter) WritePid(pid int, startTime string) error { + err := ioutil.WriteFile(filepath.Join(d.Root, "pid"), []byte(fmt.Sprint(pid)), 0655) + if err != nil { + return err + } + return ioutil.WriteFile(filepath.Join(d.Root, "start"), []byte(startTime), 0655) } func (d *DefaultStateWriter) DeletePid() error { - return os.Remove(filepath.Join(d.Root, "pid")) + err := os.Remove(filepath.Join(d.Root, "pid")) + if serr := os.Remove(filepath.Join(d.Root, "start")); err == nil { + err = serr + } + return err } From 69df6c423eb6549ab40cf7da4fb62e208c97d440 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Wed, 26 Mar 2014 06:55:46 +0000 Subject: [PATCH 2/2] Don't send prctl to be consistent with other drivers Docker-DCO-1.1-Signed-off-by: Michael Crosby (github: crosbymichael) --- nsinit/init.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/nsinit/init.go b/nsinit/init.go index 85182326..c7c2addb 100644 --- a/nsinit/init.go +++ b/nsinit/init.go @@ -54,11 +54,6 @@ func (ns *linuxNs) Init(container *libcontainer.Container, uncleanRootfs, consol return fmt.Errorf("setctty %s", err) } } - // this is our best effort to let the process know that the parent has died and that it - // should it should act on it how it sees fit - if err := system.ParentDeathSignal(uintptr(syscall.SIGTERM)); err != nil { - return fmt.Errorf("parent death signal %s", err) - } if err := setupNetwork(container, context); err != nil { return fmt.Errorf("setup networking %s", err) }