Skip to content

Commit

Permalink
Register healtcheck service before calling restore()
Browse files Browse the repository at this point in the history
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
(cherry picked from commit 7783966)
  • Loading branch information
mlaventure committed Mar 8, 2017
1 parent 33125f1 commit 595e75c
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions containerd/main.go
Original file line number Diff line number Diff line change
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 @@ -159,6 +159,17 @@ func main() {
func daemon(context *cli.Context) error {
s := make(chan os.Signal, 2048)
signal.Notify(s, syscall.SIGTERM, syscall.SIGINT)
// 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"),
context.String("runtime"),
Expand All @@ -169,6 +180,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 +190,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 {
default:
Expand All @@ -199,7 +201,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 @@ -211,7 +213,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.NewServer()
grpc_health_v1.RegisterHealthServer(s, healthServer)

Expand Down

0 comments on commit 595e75c

Please sign in to comment.