Skip to content
This repository has been archived by the owner on Jan 11, 2022. It is now read-only.

Commit

Permalink
BACKPORT: Fix BZ#1529300
Browse files Browse the repository at this point in the history
moby/moby#31662
moby/moby#31852

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
  • Loading branch information
runcom committed Jan 19, 2018
1 parent fa8fb3d commit 865d9b1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
33 changes: 19 additions & 14 deletions containerd/main.go
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/codegangsta/cli"
"github.com/cyberdelia/go-metrics-graphite"
"github.com/docker/containerd"
"github.com/docker/containerd/api/grpc/server"
grpcserver "github.com/docker/containerd/api/grpc/server"
"github.com/docker/containerd/api/grpc/types"
"github.com/docker/containerd/api/http/pprof"
"github.com/docker/containerd/supervisor"
Expand Down Expand Up @@ -157,10 +157,25 @@ func main() {
}

func daemon(context *cli.Context) error {
stateDir := context.String("state-dir")
if err := os.MkdirAll(stateDir, 0755); err != nil {
return err
}
s := make(chan os.Signal, 2048)
signal.Notify(s, syscall.SIGTERM, syscall.SIGINT, syscall.SIGPIPE)
// Split the listen string of the form proto://addr
listenSpec := context.String("listen")
listenParts := strings.SplitN(listenSpec, "://", 2)
if len(listenParts) != 2 {
return fmt.Errorf("bad listen address format %s, expected proto://address", listenSpec)
}
// Register server early to allow healthcheck to be done
server, err := startServer(listenParts[0], listenParts[1])
if err != nil {
return err
}
sv, err := supervisor.New(
context.String("state-dir"),
stateDir,
context.String("runtime"),
context.String("shim"),
context.StringSlice("runtime-args"),
Expand All @@ -169,6 +184,7 @@ func daemon(context *cli.Context) error {
if err != nil {
return err
}
types.RegisterAPIServer(server, grpcserver.NewServer(sv))
wg := &sync.WaitGroup{}
for i := 0; i < 10; i++ {
wg.Add(1)
Expand All @@ -178,16 +194,6 @@ func daemon(context *cli.Context) error {
if err := sv.Start(); err != nil {
return err
}
// Split the listen string of the form proto://addr
listenSpec := context.String("listen")
listenParts := strings.SplitN(listenSpec, "://", 2)
if len(listenParts) != 2 {
return fmt.Errorf("bad listen address format %s, expected proto://address", listenSpec)
}
server, err := startServer(listenParts[0], listenParts[1], sv)
if err != nil {
return err
}
for ss := range s {
switch ss {
case syscall.SIGPIPE:
Expand All @@ -201,7 +207,7 @@ func daemon(context *cli.Context) error {
return nil
}

func startServer(protocol, address string, sv *supervisor.Supervisor) (*grpc.Server, error) {
func startServer(protocol, address string) (*grpc.Server, error) {
// TODO: We should use TLS.
// TODO: Add an option for the SocketGroup.
sockets, err := listeners.Init(protocol, address, "", nil)
Expand All @@ -213,7 +219,6 @@ func startServer(protocol, address string, sv *supervisor.Supervisor) (*grpc.Ser
}
l := sockets[0]
s := grpc.NewServer()
types.RegisterAPIServer(s, server.NewServer(sv))
healthServer := health.NewHealthServer()
grpc_health_v1.RegisterHealthServer(s, healthServer)

Expand Down
7 changes: 3 additions & 4 deletions supervisor/supervisor.go
Expand Up @@ -21,9 +21,6 @@ const (
// New returns an initialized Process supervisor.
func New(stateDir string, runtimeName, shimName string, runtimeArgs []string, timeout time.Duration, retainCount int) (*Supervisor, error) {
startTasks := make(chan *startTask, 10)
if err := os.MkdirAll(stateDir, 0755); err != nil {
return nil, err
}
machine, err := CollectMachineInformation()
if err != nil {
return nil, err
Expand Down Expand Up @@ -334,7 +331,9 @@ func (s *Supervisor) restore() error {
id := d.Name()
container, err := runtime.Load(s.stateDir, id, s.shim, s.timeout)
if err != nil {
return err
logrus.WithFields(logrus.Fields{"error": err, "id": id}).Warnf("containerd: failed to load container,removing state directory.")
os.RemoveAll(filepath.Join(s.stateDir, id))
continue
}
processes, err := container.Processes()
if err != nil {
Expand Down

0 comments on commit 865d9b1

Please sign in to comment.