Skip to content

Connect stdout/stderr of Firecracker in Debug mode #314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions runtime/integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var defaultRuntimeConfig = Config{
CPUCount: 1,
CPUTemplate: "T2",
LogLevel: "Debug",
Debug: true,
}

func defaultSnapshotterName() string {
Expand Down
5 changes: 5 additions & 0 deletions runtime/noop_jailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ func (j noopJailer) BuildJailedMachine(cfg *Config, machineConfig *firecracker.C
WithSocketPath(relSocketPath).
Build(j.ctx)

if cfg.Debug {
cmd.Stdout = j.logger.WithField("vmm_stream", "stdout").WriterLevel(logrus.DebugLevel)
cmd.Stderr = j.logger.WithField("vmm_stream", "stderr").WriterLevel(logrus.DebugLevel)
}

j.logger.Debug("noop operation for BuildJailedMachine")
return []firecracker.Opt{
firecracker.WithProcessRunner(cmd),
Expand Down
10 changes: 8 additions & 2 deletions runtime/runc_jailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (j *runcJailer) BuildJailedMachine(cfg *Config, machineConfig *firecracker.
client := firecracker.NewClient(machineConfig.SocketPath, j.logger, machineConfig.Debug)

opts := []firecracker.Opt{
firecracker.WithProcessRunner(j.jailerCommand(vmID)),
firecracker.WithProcessRunner(j.jailerCommand(vmID, cfg.Debug)),
firecracker.WithClient(client),
func(m *firecracker.Machine) {
m.Handlers.FcInit = m.Handlers.FcInit.Prepend(handler)
Expand Down Expand Up @@ -340,9 +340,15 @@ func copyFile(src, dst string, mode os.FileMode) error {
return nil
}

func (j runcJailer) jailerCommand(containerName string) *exec.Cmd {
func (j runcJailer) jailerCommand(containerName string, isDebug bool) *exec.Cmd {
cmd := exec.CommandContext(j.ctx, j.runcBinaryPath, "run", containerName)
cmd.Dir = j.OCIBundlePath()

if isDebug {
cmd.Stdout = j.logger.WithField("vmm_stream", "stdout").WriterLevel(logrus.DebugLevel)
cmd.Stderr = j.logger.WithField("vmm_stream", "stderr").WriterLevel(logrus.DebugLevel)
}

return cmd
}

Expand Down