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:
parent
345365e7b0
commit
b16b1a04ff
3 changed files with 44 additions and 5 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue