mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-23 19:05:37 +00:00
service: log stdout and stderr to separate files
Previously we would pass the path `/var/log/service.log` for both
stdout and stderr to containerd. containerd would construct a dict
with the paths as keys[1] and, due to the duplicate key, would only
open one of the files and start one `io.Copy` instance. Writes to
the other stream would be buffered by the pipe connected to
containerd-shim and would eventually block.
If we modified containerd to open the file twice and start 2
`io.Copy` instances, we would end up with the two streams interleaved
together. It seems cleaner to keep the streams separate; therefore
this patch logs stdout to `/var/log/service.out.log` and stderr to
`/var/log/service.err.log`.
[1]
49437711c3/linux/shim/io.go (L51)
Signed-off-by: David Scott <dave.scott@docker.com>
This commit is contained in:
parent
3b097e6056
commit
9c35dbaac2
@ -121,17 +121,21 @@ func start(service, sock, basePath, dumpSpec string) (string, uint32, string, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
io := func(id string) (containerd.IO, error) {
|
io := func(id string) (containerd.IO, error) {
|
||||||
logfile := filepath.Join("/var/log", service+".log")
|
stdoutFile := filepath.Join("/var/log", service+".out.log")
|
||||||
// We just need this to exist.
|
stderrFile := filepath.Join("/var/log", service+".err.log")
|
||||||
if err := ioutil.WriteFile(logfile, []byte{}, 0600); err != nil {
|
// We just need this to exist. If we cannot write to the directory,
|
||||||
// if we cannot write to log, discard output
|
// we'll discard output instead.
|
||||||
logfile = "/dev/null"
|
if err := ioutil.WriteFile(stdoutFile, []byte{}, 0600); err != nil {
|
||||||
|
stdoutFile = "/dev/null"
|
||||||
|
}
|
||||||
|
if err := ioutil.WriteFile(stderrFile, []byte{}, 0600); err != nil {
|
||||||
|
stderrFile = "/dev/null"
|
||||||
}
|
}
|
||||||
return &cio{
|
return &cio{
|
||||||
containerd.IOConfig{
|
containerd.IOConfig{
|
||||||
Stdin: "/dev/null",
|
Stdin: "/dev/null",
|
||||||
Stdout: logfile,
|
Stdout: stdoutFile,
|
||||||
Stderr: logfile,
|
Stderr: stderrFile,
|
||||||
Terminal: false,
|
Terminal: false,
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user