From 05be5bf1f9f9184181816f12ac8d440010de9aa0 Mon Sep 17 00:00:00 2001 From: Fupan Li Date: Mon, 17 Dec 2018 06:10:51 +0000 Subject: [PATCH] shimv2: discard log before shim init log output containerd would like to get the shim's socket address from shimv2's stdout, thus it's better to discard the log's output before shimv2 init it's logger and at the same time add a hook to log into syslog. Fixes: #1035 Signed-off-by: Fupan Li --- containerd-shim-v2/service.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/containerd-shim-v2/service.go b/containerd-shim-v2/service.go index 375a670d7..f1790b8a2 100644 --- a/containerd-shim-v2/service.go +++ b/containerd-shim-v2/service.go @@ -8,6 +8,7 @@ package containerdshim import ( "context" "encoding/json" + "io/ioutil" "os" sysexec "os/exec" "path/filepath" @@ -56,9 +57,13 @@ var vci vc.VC = &vc.VCImpl{} // New returns a new shim service that can be used via GRPC func New(ctx context.Context, id string, publisher events.Publisher) (cdshim.Shim, error) { logger := logrus.WithField("ID", id) + // Discard the log before shim init its log output. Otherwise + // it will output into stdio, from which containerd would like + // to get the shim's socket address. + logrus.SetOutput(ioutil.Discard) vci.SetLogger(ctx, logger) katautils.SetLogger(ctx, logger, logger.Logger.Level) - _, runtimeConfig, err := katautils.LoadConfiguration("", true, true) + _, runtimeConfig, err := katautils.LoadConfiguration("", false, true) if err != nil { return nil, err }