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: all:
mkdir -p bin/ 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 cd ctr && go build -o ../bin/ctr
client: client:
@ -10,7 +12,7 @@ client:
daemon: daemon:
mkdir -p bin/ mkdir -p bin/
cd containerd && go build -tags libcontainer -o ../bin/containerd cd containerd && go build -tags "$(BUILDTAGS)" -o ../bin/containerd
install: install:
cp bin/* /usr/local/bin/ 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) return p.cmd.Process.Signal(s)
} }
func (p *runcProcess) Close() error {
return nil
}
type runcRuntime struct { type runcRuntime struct {
stateDir string stateDir string
} }
@ -143,19 +147,22 @@ func (r *runcRuntime) Type() string {
return "runc" return "runc"
} }
func (r *runcRuntime) Create(id, bundlePath string, stdio *runtime.Stdio) (runtime.Container, error) { func (r *runcRuntime) Create(id, bundlePath string) (runtime.Container, *runtime.IO, error) {
cmd := exec.Command("runc", "--root", r.stateDir, "--id", id, "start")
cmd.Dir = bundlePath
// cmd.Stderr = stdio.Stderr
// cmd.Stdout = stdio.Stdout
var s specs.Spec var s specs.Spec
f, err := os.Open(filepath.Join(bundlePath, "config.json")) f, err := os.Open(filepath.Join(bundlePath, "config.json"))
if err != nil { if err != nil {
return nil, err return nil, nil, err
} }
defer f.Close() defer f.Close()
if err := json.NewDecoder(f).Decode(&s); err != nil { 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{ return &runcContainer{
id: id, id: id,
@ -166,35 +173,59 @@ func (r *runcRuntime) Create(id, bundlePath string, stdio *runtime.Stdio) (runti
spec: s.Process, spec: s.Process,
}, },
processes: make(map[int]*runcProcess), processes: make(map[int]*runcProcess),
}, nil }, i, nil
} }
func (r *runcRuntime) StartProcess(ci runtime.Container, p specs.Process, stdio *runtime.Stdio) (runtime.Process, error) { func (r *runcRuntime) createIO(cmd *exec.Cmd) (*runtime.IO, error) {
c, ok := ci.(*runcContainer) w, err := cmd.StdinPipe()
if !ok {
return nil, runtime.ErrInvalidContainerType
}
f, err := ioutil.TempFile("", "containerd")
if err != nil { if err != nil {
return nil, err return nil, err
} }
if err := json.NewEncoder(f).Encode(p); err != nil { ro, err := cmd.StdoutPipe()
f.Close() if err != nil {
return nil, err 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() 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{ process := &runcProcess{
cmd: cmd, cmd: cmd,
spec: p, spec: p,
} }
if err := cmd.Start(); err != nil { if err := cmd.Start(); err != nil {
return nil, err return nil, nil, err
} }
pid, err := process.Pid() pid, err := process.Pid()
if err != nil { if err != nil {
return nil, err return nil, nil, err
} }
c.processes[pid] = process c.processes[pid] = process
return process, nil return process, i, nil
} }