Merge pull request #144 from docker/handle-term

Handle term signals and update documentation
This commit is contained in:
Michael Crosby 2016-03-21 16:44:28 -07:00
commit 54c213e8a7
7 changed files with 64 additions and 71 deletions

View file

@ -176,7 +176,7 @@
END OF TERMS AND CONDITIONS END OF TERMS AND CONDITIONS
Copyright 2013-2015 Docker, Inc. Copyright 2013-2016 Docker, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

View file

@ -9,10 +9,12 @@
# This file is compiled into the MAINTAINERS file in docker/opensource. # This file is compiled into the MAINTAINERS file in docker/opensource.
# #
[Org] [Org]
[Org."Core maintainers"] [Org."Core maintainers"]
people = [ people = [
"crosbymichael", "crosbymichael",
] "tonistiigi",
"mlaventure",
]
[people] [people]
@ -22,7 +24,18 @@
# ADD YOURSELF HERE IN ALPHABETICAL ORDER # ADD YOURSELF HERE IN ALPHABETICAL ORDER
[people.crosbymichael] [people.crosbymichael]
Name = "Michael Crosby" Name = "Michael Crosby"
Email = "crosbymichael@gmail.com" Email = "crosbymichael@gmail.com"
GitHub = "crosbymichael" GitHub = "crosbymichael"
[people.tonistiigi]
Name = "Tõnis Tiigi"
Email = "tonis@docker.com"
GitHub = "tonistiigi"
[people.mlaventure]
Name = "Kenfe-Mickaël Laventure"
Email = "mickael.laventure@docker.com"
GitHub = "mlaventure"

View file

@ -1,18 +1,9 @@
# containerd # containerd
Containerd is a daemon to control runC, built for performance and density. Containerd is a daemon to control runC, built for performance and density.
Containerd leverages runC advanced features such as seccomp and user namespace support as well Containerd leverages runC's advanced features such as seccomp and user namespace support as well
as checkpoint and restore for cloning and live migration of containers. as checkpoint and restore for cloning and live migration of containers.
#### Status
*alpha*
What does alpha, beta, etc mean?
* alpha - not feature complete
* beta - feature complete but needs testing
* prod ready - ready for production
## Docs ## Docs
For more documentation on various subjects refer to the `/docs` directory in this repository. For more documentation on various subjects refer to the `/docs` directory in this repository.
@ -348,7 +339,7 @@ commit automatically with `git commit -s`.
## Copyright and license ## Copyright and license
Copyright © 2015 Docker, Inc. All rights reserved, except as follows. Code Copyright © 2016 Docker, Inc. All rights reserved, except as follows. Code
is released under the Apache 2.0 license. The README.md file, and files in the is released under the Apache 2.0 license. The README.md file, and files in the
"docs" folder are licensed under the Creative Commons Attribution 4.0 "docs" folder are licensed under the Creative Commons Attribution 4.0
International License under the terms and conditions set forth in the file International License under the terms and conditions set forth in the file

View file

@ -4,7 +4,9 @@ import (
"fmt" "fmt"
"net" "net"
"os" "os"
"os/signal"
"sync" "sync"
"syscall"
"time" "time"
"google.golang.org/grpc" "google.golang.org/grpc"
@ -14,6 +16,7 @@ import (
"github.com/docker/containerd" "github.com/docker/containerd"
"github.com/docker/containerd/api/grpc/server" "github.com/docker/containerd/api/grpc/server"
"github.com/docker/containerd/api/grpc/types" "github.com/docker/containerd/api/grpc/types"
"github.com/docker/containerd/osutils"
"github.com/docker/containerd/supervisor" "github.com/docker/containerd/supervisor"
) )
@ -80,7 +83,11 @@ func main() {
func daemon(address, stateDir string, concurrency int, runtimeName string) error { func daemon(address, stateDir string, concurrency int, runtimeName string) error {
// setup a standard reaper so that we don't leave any zombies if we are still alive // setup a standard reaper so that we don't leave any zombies if we are still alive
// this is just good practice because we are spawning new processes // this is just good practice because we are spawning new processes
go reapProcesses() s := make(chan os.Signal, 2048)
signal.Notify(s, syscall.SIGCHLD, syscall.SIGTERM, syscall.SIGINT)
if err := osutils.SetSubreaper(1); err != nil {
logrus.WithField("error", err).Error("containerd: set subpreaper")
}
sv, err := supervisor.New(stateDir, runtimeName) sv, err := supervisor.New(stateDir, runtimeName)
if err != nil { if err != nil {
return err return err
@ -94,17 +101,42 @@ func daemon(address, stateDir string, concurrency int, runtimeName string) error
if err := sv.Start(); err != nil { if err := sv.Start(); err != nil {
return err return err
} }
if err := os.RemoveAll(address); err != nil { server, err := startServer(address, sv)
return err
}
l, err := net.Listen(defaultListenType, address)
if err != nil { if err != nil {
return err return err
} }
for ss := range s {
switch ss {
case syscall.SIGCHLD:
if _, err := osutils.Reap(); err != nil {
logrus.WithField("error", err).Warn("containerd: reap child processes")
}
default:
logrus.Infof("stopping containerd after receiving %s", ss)
server.Stop()
os.Exit(0)
}
}
return nil
}
func startServer(address string, sv *supervisor.Supervisor) (*grpc.Server, error) {
if err := os.RemoveAll(address); err != nil {
return nil, err
}
l, err := net.Listen(defaultListenType, address)
if err != nil {
return nil, err
}
s := grpc.NewServer() s := grpc.NewServer()
types.RegisterAPIServer(s, server.NewServer(sv)) types.RegisterAPIServer(s, server.NewServer(sv))
logrus.Debugf("containerd: grpc api on %s", address) go func() {
return s.Serve(l) logrus.Debugf("containerd: grpc api on %s", address)
if err := s.Serve(l); err != nil {
logrus.WithField("error", err).Fatal("containerd: serve grpc")
}
}()
return s, nil
} }
// getDefaultID returns the hostname for the instance host // getDefaultID returns the hostname for the instance host

View file

@ -4,7 +4,6 @@ import (
"log" "log"
"net" "net"
"os" "os"
"os/signal"
"runtime" "runtime"
"syscall" "syscall"
"time" "time"
@ -62,19 +61,6 @@ func checkLimits() error {
return nil return nil
} }
func reapProcesses() {
s := make(chan os.Signal, 2048)
signal.Notify(s, syscall.SIGCHLD)
if err := osutils.SetSubreaper(1); err != nil {
logrus.WithField("error", err).Error("containerd: set subpreaper")
}
for range s {
if _, err := osutils.Reap(); err != nil {
logrus.WithField("error", err).Error("containerd: reap child processes")
}
}
}
func processMetrics() { func processMetrics() {
var ( var (
g = metrics.NewGauge() g = metrics.NewGauge()

View file

@ -1,29 +0,0 @@
package main
import (
"os"
"github.com/codegangsta/cli"
)
var defaultStateDir = os.Getenv("PROGRAMDATA") + `\docker\containerd`
const (
defaultListenType = "tcp"
defaultGRPCEndpoint = "localhost:2377"
)
func appendPlatformFlags() {
}
// TODO Windows: May be able to factor out entirely
func checkLimits() error {
return nil
}
// No idea how to implement this on Windows.
func reapProcesses() {
}
func setAppBefore(app *cli.App) {
}

View file

@ -1,5 +1,5 @@
package containerd package containerd
const Version = "0.0.5" const Version = "0.1.0"
var GitCommit = "" var GitCommit = ""