Merge pull request #14 from LK4D4/add_logging
Add logging and more info
This commit is contained in:
commit
f8ee26ffca
7 changed files with 41 additions and 6 deletions
|
@ -103,6 +103,9 @@ func daemon(id, stateDir string, concurrency, bufferSize int) error {
|
|||
}
|
||||
// only set containerd as the subreaper if it is not an init process
|
||||
if pid := os.Getpid(); pid != 1 {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"pid": pid,
|
||||
}).Debug("containerd is not init, set as subreaper")
|
||||
if err := setSubReaper(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -14,7 +14,9 @@ import (
|
|||
)
|
||||
|
||||
func startSignalHandler(supervisor *containerd.Supervisor, bufferSize int) {
|
||||
logrus.Debug("containerd: starting signal handler")
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"bufferSize": bufferSize,
|
||||
}).Debug("containerd: starting signal handler")
|
||||
signals := make(chan os.Signal, bufferSize)
|
||||
signal.Notify(signals)
|
||||
for s := range signals {
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/containerd/runtime"
|
||||
"github.com/opencontainers/runc/libcontainer"
|
||||
"github.com/opencontainers/runc/libcontainer/configs"
|
||||
|
@ -356,6 +357,10 @@ type libcontainerRuntime struct {
|
|||
factory libcontainer.Factory
|
||||
}
|
||||
|
||||
func (r *libcontainerRuntime) Type() string {
|
||||
return "libcontainer"
|
||||
}
|
||||
|
||||
func (r *libcontainerRuntime) Create(id, bundlePath string, stdio *runtime.Stdio) (runtime.Container, error) {
|
||||
spec, rspec, err := r.loadSpec(
|
||||
filepath.Join(bundlePath, "config.json"),
|
||||
|
@ -364,13 +369,17 @@ func (r *libcontainerRuntime) Create(id, bundlePath string, stdio *runtime.Stdio
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"id": id,
|
||||
"bundlePath": bundlePath,
|
||||
}).Debugf("create container")
|
||||
config, err := r.createLibcontainerConfig(id, bundlePath, spec, rspec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
container, err := r.factory.Create(id, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("create container: %v", err)
|
||||
}
|
||||
process, err := r.newProcess(spec.Process, stdio)
|
||||
if err != nil {
|
||||
|
@ -422,14 +431,14 @@ func (r *libcontainerRuntime) newProcess(p specs.Process, stdio *runtime.Stdio)
|
|||
if stdio.Stdout != "" {
|
||||
f, err := os.OpenFile(stdio.Stdout, os.O_CREATE|os.O_WRONLY, 0755)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("open stdout: %v", err)
|
||||
}
|
||||
stdout = f
|
||||
}
|
||||
if stdio.Stderr != "" {
|
||||
f, err := os.OpenFile(stdio.Stderr, os.O_CREATE|os.O_WRONLY, 0755)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("open stderr: %v", err)
|
||||
}
|
||||
stderr = f
|
||||
}
|
||||
|
@ -467,10 +476,10 @@ func (r *libcontainerRuntime) loadSpec(cPath, rPath string) (spec *specs.LinuxSp
|
|||
defer rf.Close()
|
||||
|
||||
if err = json.NewDecoder(cf).Decode(&spec); err != nil {
|
||||
return spec, rspec, err
|
||||
return spec, rspec, fmt.Errorf("unmarshal %s: %v", cPath, err)
|
||||
}
|
||||
if err = json.NewDecoder(rf).Decode(&rspec); err != nil {
|
||||
return spec, rspec, err
|
||||
return spec, rspec, fmt.Errorf("unmarshal %s: %v", rPath, err)
|
||||
}
|
||||
return spec, rspec, r.checkSpecVersion(spec)
|
||||
}
|
||||
|
|
|
@ -139,6 +139,10 @@ type runcRuntime struct {
|
|||
stateDir string
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -20,4 +20,5 @@ type Runtime interface {
|
|||
Create(id, bundlePath string, stdio *Stdio) (Container, error)
|
||||
// StartProcess adds a new process to the container
|
||||
StartProcess(Container, specs.Process, *Stdio) (Process, error)
|
||||
Type() string
|
||||
}
|
||||
|
|
|
@ -133,6 +133,12 @@ func (s *Supervisor) Start() error {
|
|||
// so that nothing else is scheduled over the top of it.
|
||||
goruntime.LockOSThread()
|
||||
for e := range s.events {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"type": e.Type,
|
||||
"timestamp": e.Timestamp,
|
||||
"id": e.ID,
|
||||
"bundlePath": e.BundlePath,
|
||||
}).Debug("event received")
|
||||
EventsCounter.Inc(1)
|
||||
h, ok := s.handlers[e.Type]
|
||||
if !ok {
|
||||
|
@ -149,6 +155,10 @@ func (s *Supervisor) Start() error {
|
|||
close(e.Err)
|
||||
}
|
||||
}()
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"runtime": s.runtime.Type(),
|
||||
"stateDir": s.stateDir,
|
||||
}).Debug("Supervisor started")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/containerd/runtime"
|
||||
)
|
||||
|
||||
|
@ -33,6 +34,11 @@ func (w *worker) Start() {
|
|||
defer w.wg.Done()
|
||||
for t := range w.s.tasks {
|
||||
started := time.Now()
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"containerID": t.Container.ID(),
|
||||
"checkpoint": t.Checkpoint,
|
||||
"started": started,
|
||||
}).Debug("worker received task")
|
||||
if t.Checkpoint != "" {
|
||||
if err := t.Container.Restore(t.Checkpoint); err != nil {
|
||||
evt := NewEvent(DeleteEventType)
|
||||
|
|
Loading…
Reference in a new issue