Add logging to runc runtime

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2015-12-11 13:59:19 -08:00
parent c425446c8e
commit 15080cda61
2 changed files with 55 additions and 22 deletions

View File

@ -1,7 +1,9 @@
BUILDTAGS=libcontainer
all:
mkdir -p bin/
cd containerd && go build -tags libcontainer -o ../bin/containerd
cd containerd && go build -tags "$(BUILDTAGS)" -o ../bin/containerd
cd ctr && go build -o ../bin/ctr
client:
@ -10,7 +12,7 @@ client:
daemon:
mkdir -p bin/
cd containerd && go build -tags libcontainer -o ../bin/containerd
cd containerd && go build -tags "$(BUILDTAGS)" -o ../bin/containerd
install:
cp bin/* /usr/local/bin/

View File

@ -135,6 +135,10 @@ func (p *runcProcess) Signal(s os.Signal) error {
return p.cmd.Process.Signal(s)
}
func (p *runcProcess) Close() error {
return nil
}
type runcRuntime struct {
stateDir string
}
@ -143,19 +147,22 @@ func (r *runcRuntime) Type() string {
return "runc"
}
func (r *runcRuntime) Create(id, bundlePath string, stdio *runtime.Stdio) (runtime.Container, error) {
cmd := exec.Command("runc", "--root", r.stateDir, "--id", id, "start")
cmd.Dir = bundlePath
// cmd.Stderr = stdio.Stderr
// cmd.Stdout = stdio.Stdout
func (r *runcRuntime) Create(id, bundlePath string) (runtime.Container, *runtime.IO, error) {
var s specs.Spec
f, err := os.Open(filepath.Join(bundlePath, "config.json"))
if err != nil {
return nil, err
return nil, nil, err
}
defer f.Close()
if err := json.NewDecoder(f).Decode(&s); err != nil {
return nil, err
return nil, nil, err
}
cmd := exec.Command("runc", "--root", r.stateDir, "--id", id, "start")
cmd.Dir = bundlePath
i, err := r.createIO(cmd)
if err != nil {
return nil, nil, err
}
return &runcContainer{
id: id,
@ -166,35 +173,59 @@ func (r *runcRuntime) Create(id, bundlePath string, stdio *runtime.Stdio) (runti
spec: s.Process,
},
processes: make(map[int]*runcProcess),
}, nil
}, i, nil
}
func (r *runcRuntime) StartProcess(ci runtime.Container, p specs.Process, stdio *runtime.Stdio) (runtime.Process, error) {
c, ok := ci.(*runcContainer)
if !ok {
return nil, runtime.ErrInvalidContainerType
}
f, err := ioutil.TempFile("", "containerd")
func (r *runcRuntime) createIO(cmd *exec.Cmd) (*runtime.IO, error) {
w, err := cmd.StdinPipe()
if err != nil {
return nil, err
}
if err := json.NewEncoder(f).Encode(p); err != nil {
f.Close()
ro, err := cmd.StdoutPipe()
if err != nil {
return nil, err
}
cmd := c.newCommand("exec", f.Name())
re, err := cmd.StderrPipe()
if err != nil {
return nil, err
}
return &runtime.IO{
Stdin: w,
Stdout: ro,
Stderr: re,
}, nil
}
func (r *runcRuntime) StartProcess(ci runtime.Container, p specs.Process) (runtime.Process, *runtime.IO, error) {
c, ok := ci.(*runcContainer)
if !ok {
return nil, nil, runtime.ErrInvalidContainerType
}
f, err := ioutil.TempFile("", "containerd")
if err != nil {
return nil, nil, err
}
err = json.NewEncoder(f).Encode(p)
f.Close()
if err != nil {
return nil, nil, err
}
cmd := c.newCommand("exec", f.Name())
i, err := r.createIO(cmd)
if err != nil {
return nil, nil, err
}
process := &runcProcess{
cmd: cmd,
spec: p,
}
if err := cmd.Start(); err != nil {
return nil, err
return nil, nil, err
}
pid, err := process.Pid()
if err != nil {
return nil, err
return nil, nil, err
}
c.processes[pid] = process
return process, nil
return process, i, nil
}