diff --git a/docs/faq.md b/docs/faq.md index c459bd9bb..0c1f9e08e 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -37,6 +37,29 @@ If you're not seeing `containerd` logs in the console during boot, make sure tha `init` and other processes like `containerd` will use the last defined console in the kernel `cmdline`. When using `qemu`, to see the console you need to list `ttyS0` as the last console to properly see the output. +## Enabling debug or trace log levels on containerd + +On startup, linuxkit looks for and parses a file `/etc/containerd/cli-opts`. If it exists, the content is used as arguments to containerd. Thus, to enable +a higher log level, for example `debug`, create a file whose contents are `--log-level debug` and place it on the image: + +```yml +files: + - path: /etc/containerd/cli-opts + contents: "--log-level debug" +``` + +Note that the package that parses the contents splits on _all_ whitespace. It does not, as of this writing, support shell-like parsing, so the following will work: + +``` +--log-level debug --arg abcd +``` + +while the following will not: + +``` +--log-level debug --arg 'abcd def' +``` + ## Troubleshooting containers Linuxkit runs all services in a specific `containerd` namespace called `services.linuxkit`. To list all the defined containers: diff --git a/pkg/init/cmd/service/system_init.go b/pkg/init/cmd/service/system_init.go index 3ca71b50c..21670b78b 100644 --- a/pkg/init/cmd/service/system_init.go +++ b/pkg/init/cmd/service/system_init.go @@ -8,6 +8,7 @@ import ( "os" "os/exec" "path/filepath" + "strings" "syscall" "time" @@ -17,6 +18,10 @@ import ( log "github.com/sirupsen/logrus" ) +const ( + containerdOptsFile = "/etc/containerd/cli-opts" +) + func cleanupTask(ctx context.Context, ctr containerd.Container) error { task, err := ctr.Task(ctx, nil) if err != nil { @@ -78,8 +83,14 @@ func systemInitCmd(ctx context.Context, args []string) { // remove (unlikely) old containerd socket _ = os.Remove(*sock) + // look for containerd options + ctrdArgs := []string{} + if b, err := ioutil.ReadFile(containerdOptsFile); err != nil { + ctrdArgs = strings.Fields(string(b)) + } + // start up containerd - cmd := exec.Command(*binary) + cmd := exec.Command(*binary, ctrdArgs...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr if err := cmd.Start(); err != nil {