containerd-shim: redirect output into stdout fifo

Redirect is used to make sure that containerd still can read the log of
shim after restart.

Signed-off-by: Wei Fu <fuweid89@gmail.com>
This commit is contained in:
Wei Fu 2019-05-12 23:03:28 +08:00
parent bc944553a8
commit fbb80b9510

View File

@ -110,6 +110,10 @@ func main() {
stderr.Close() stderr.Close()
}() }()
// redirect the following output into fifo to make sure that containerd
// still can read the log after restart
logrus.SetOutput(stdout)
if err := executeShim(); err != nil { if err := executeShim(); err != nil {
fmt.Fprintf(os.Stderr, "containerd-shim: %s\n", err) fmt.Fprintf(os.Stderr, "containerd-shim: %s\n", err)
os.Exit(1) os.Exit(1)
@ -119,7 +123,7 @@ func main() {
// If containerd server process dies, we need the shim to keep stdout/err reader // If containerd server process dies, we need the shim to keep stdout/err reader
// FDs so that Linux does not SIGPIPE the shim process if it tries to use its end of // FDs so that Linux does not SIGPIPE the shim process if it tries to use its end of
// these pipes. // these pipes.
func openStdioKeepAlivePipes(dir string) (io.ReadCloser, io.ReadCloser, error) { func openStdioKeepAlivePipes(dir string) (io.ReadWriteCloser, io.ReadWriteCloser, error) {
background := context.Background() background := context.Background()
keepStdoutAlive, err := shimlog.OpenShimStdoutLog(background, dir) keepStdoutAlive, err := shimlog.OpenShimStdoutLog(background, dir)
if err != nil { if err != nil {