Skip to content

Commit c699faf

Browse files
Add support for {nomad alloc logs} command.
1 parent 3c0fc2a commit c699faf

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

containerd/containerd.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package containerd
1919

2020
import (
2121
"fmt"
22+
"os"
23+
"syscall"
2224

2325
"github.com/containerd/containerd"
2426
"github.com/containerd/containerd/cio"
@@ -120,8 +122,24 @@ func (d *Driver) loadContainer(id string) (containerd.Container, error) {
120122
return d.client.LoadContainer(d.ctxContainerd, id)
121123
}
122124

123-
func (d *Driver) createTask(container containerd.Container) (containerd.Task, error) {
124-
return container.NewTask(d.ctxContainerd, cio.NewCreator(cio.WithStdio))
125+
func (d *Driver) createTask(container containerd.Container, stdoutPath, stderrPath string) (containerd.Task, error) {
126+
stdout, err := openFIFO(stdoutPath)
127+
if err != nil {
128+
return nil, err
129+
}
130+
131+
stderr, err := openFIFO(stderrPath)
132+
if err != nil {
133+
return nil, err
134+
}
135+
136+
return container.NewTask(d.ctxContainerd, cio.NewCreator(cio.WithStreams(nil, stdout, stderr)))
137+
}
138+
139+
// FIFO's are named pipes in linux.
140+
// openFIFO() opens the nomad task stdout/stderr pipes and returns the fd.
141+
func openFIFO(path string) (*os.File, error) {
142+
return os.OpenFile(path, os.O_RDWR|syscall.O_NONBLOCK, 0600)
125143
}
126144

127145
func (d *Driver) getTask(container containerd.Container) (containerd.Task, error) {

containerd/driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
359359

360360
d.logger.Info(fmt.Sprintf("Successfully created container with name: %s", containerName))
361361

362-
task, err := d.createTask(container)
362+
task, err := d.createTask(container, cfg.StdoutPath, cfg.StderrPath)
363363
if err != nil {
364364
return nil, nil, fmt.Errorf("Error in creating task: %v", err)
365365
}

0 commit comments

Comments
 (0)