Skip to content

Commit 865ed8a

Browse files
committed
add containerd cli opts
Signed-off-by: Avi Deitcher <avi@deitcher.net>
1 parent a1427d0 commit 865ed8a

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

docs/faq.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,29 @@ If you're not seeing `containerd` logs in the console during boot, make sure tha
3737

3838
`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.
3939

40+
## Enabling debug or trace log levels on containerd
41+
42+
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
43+
a higher log level, for example `debug`, create a file whose contents are `--log-level debug` and place it on the image:
44+
45+
```yml
46+
files:
47+
- path: /etc/containerd/cli-opts
48+
contents: "--log-level debug"
49+
```
50+
51+
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:
52+
53+
```
54+
--log-level debug --arg abcd
55+
```
56+
57+
while the following will not:
58+
59+
```
60+
--log-level debug --arg 'abcd def'
61+
```
62+
4063
## Troubleshooting containers
4164

4265
Linuxkit runs all services in a specific `containerd` namespace called `services.linuxkit`. To list all the defined containers:

pkg/init/cmd/service/system_init.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"os/exec"
1010
"path/filepath"
11+
"strings"
1112
"syscall"
1213
"time"
1314

@@ -17,6 +18,10 @@ import (
1718
log "github.com/sirupsen/logrus"
1819
)
1920

21+
const (
22+
containerdOptsFile = "/etc/containerd/cli-opts"
23+
)
24+
2025
func cleanupTask(ctx context.Context, ctr containerd.Container) error {
2126
task, err := ctr.Task(ctx, nil)
2227
if err != nil {
@@ -78,8 +83,14 @@ func systemInitCmd(ctx context.Context, args []string) {
7883
// remove (unlikely) old containerd socket
7984
_ = os.Remove(*sock)
8085

86+
// look for containerd options
87+
ctrdArgs := []string{}
88+
if b, err := ioutil.ReadFile(containerdOptsFile); err != nil {
89+
ctrdArgs = strings.Fields(string(b))
90+
}
91+
8192
// start up containerd
82-
cmd := exec.Command(*binary)
93+
cmd := exec.Command(*binary, ctrdArgs...)
8394
cmd.Stdout = os.Stdout
8495
cmd.Stderr = os.Stderr
8596
if err := cmd.Start(); err != nil {

0 commit comments

Comments
 (0)