Remove container on load if it exited
If the shim gets sigkilled while containerd is down we need to be able to remove the container correctly so that it does not stay in a stopped state forever. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"syscall"
|
||||
|
||||
"github.com/docker/containerd/specs"
|
||||
)
|
||||
@@ -36,6 +37,8 @@ type Process interface {
|
||||
Stdio() Stdio
|
||||
// SystemPid is the pid on the system
|
||||
SystemPid() int
|
||||
// State returns if the process is running or not
|
||||
State() State
|
||||
}
|
||||
|
||||
type processConfig struct {
|
||||
@@ -178,6 +181,17 @@ func (p *process) Close() error {
|
||||
return p.exitPipe.Close()
|
||||
}
|
||||
|
||||
func (p *process) State() State {
|
||||
if p.pid == 0 {
|
||||
return Stopped
|
||||
}
|
||||
err := syscall.Kill(p.pid, 0)
|
||||
if err != nil && err == syscall.ESRCH {
|
||||
return Stopped
|
||||
}
|
||||
return Running
|
||||
}
|
||||
|
||||
func (p *process) getPidFromFile() (int, error) {
|
||||
data, err := ioutil.ReadFile(filepath.Join(p.root, "pid"))
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user