Refactor process.go for platform specific

Signed-off-by: John Howard <jhoward@microsoft.com>

Move process sorter to new file

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>

Sort containers by id

This will not be the most accurate sorting but atleast the list will be
consistent inbetween calls.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>

Allow runtime to be configurable via daemon start

This allows people to pass an alternate name or location to the runtime
binary to start containers.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>

Fix state output for containers

Return the proper state/status for a container by checking if the pid is
still alive.  Also fix the cleanup handling in the shim to make sure
containers are not left behind.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>

Properly wait for container start

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
John Howard 2016-02-25 12:59:34 -08:00 committed by Michael Crosby
parent 0ad7654f80
commit b044ff0f29
19 changed files with 323 additions and 206 deletions

View file

@ -5,6 +5,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"syscall"
"github.com/Sirupsen/logrus"
)
@ -42,6 +43,8 @@ type Container interface {
Pids() ([]int, error)
// Stats returns realtime container stats and resource information
Stats() (*Stat, error)
// Name or path of the OCI compliant runtime used to execute the container
Runtime() string
// OOM signals the channel if the container received an OOM notification
// OOM() (<-chan struct{}, error)
}
@ -68,13 +71,14 @@ func NewStdio(stdin, stdout, stderr string) Stdio {
}
// New returns a new container
func New(root, id, bundle string, labels []string) (Container, error) {
func New(root, id, bundle, runtimeName string, labels []string) (Container, error) {
c := &container{
root: root,
id: id,
bundle: bundle,
labels: labels,
processes: make(map[string]*process),
runtime: runtimeName,
}
if err := os.Mkdir(filepath.Join(root, id), 0755); err != nil {
return nil, err
@ -85,8 +89,9 @@ func New(root, id, bundle string, labels []string) (Container, error) {
}
defer f.Close()
if err := json.NewEncoder(f).Encode(state{
Bundle: bundle,
Labels: labels,
Bundle: bundle,
Labels: labels,
Runtime: runtimeName,
}); err != nil {
return nil, err
}
@ -108,6 +113,7 @@ func Load(root, id string) (Container, error) {
id: id,
bundle: s.Bundle,
labels: s.Labels,
runtime: s.Runtime,
processes: make(map[string]*process),
}
dirs, err := ioutil.ReadDir(filepath.Join(root, id))
@ -151,6 +157,7 @@ type container struct {
root string
id string
bundle string
runtime string
processes map[string]*process
stdio Stdio
labels []string
@ -182,6 +189,14 @@ func (c *container) readSpec() (*PlatformSpec, error) {
}
func (c *container) State() State {
proc := c.processes["init"]
if proc == nil || proc.pid == 0 {
return Stopped
}
err := syscall.Kill(proc.pid, 0)
if err != nil && err == syscall.ESRCH {
return Stopped
}
return Running
}