diff --git a/libcontainerd/client_windows.go b/libcontainerd/client_windows.go index 67ebb5998d..a721b4a8cc 100644 --- a/libcontainerd/client_windows.go +++ b/libcontainerd/client_windows.go @@ -439,6 +439,11 @@ func (clnt *client) AddProcess(ctx context.Context, containerID, processFriendly if err != nil { return -1, err } + + defer func() { + container.debugGCS() + }() + // Note we always tell HCS to // create stdout as it's required regardless of '-i' or '-t' options, so that // docker can always grab the output through logs. We also tell HCS to always diff --git a/libcontainerd/container_windows.go b/libcontainerd/container_windows.go index 06f9c82209..5eeb4736f6 100644 --- a/libcontainerd/container_windows.go +++ b/libcontainerd/container_windows.go @@ -50,6 +50,7 @@ func (ctr *container) start(attachStdio StdioCallback) error { logrus.Debugln("libcontainerd: starting container ", ctr.containerID) if err = ctr.hcsContainer.Start(); err != nil { logrus.Errorf("libcontainerd: failed to start container: %s", err) + ctr.debugGCS() // Before terminating! if err := ctr.terminate(); err != nil { logrus.Errorf("libcontainerd: failed to cleanup after a failed Start. %s", err) } else { @@ -58,6 +59,10 @@ func (ctr *container) start(attachStdio StdioCallback) error { return err } + defer func() { + ctr.debugGCS() + }() + // Note we always tell HCS to // create stdout as it's required regardless of '-i' or '-t' options, so that // docker can always grab the output through logs. We also tell HCS to always diff --git a/libcontainerd/utils_windows.go b/libcontainerd/utils_windows.go index aa2fe422a6..fc2869b6b4 100644 --- a/libcontainerd/utils_windows.go +++ b/libcontainerd/utils_windows.go @@ -1,6 +1,10 @@ package libcontainerd -import "strings" +import ( + "strings" + + opengcs "github.com/Microsoft/opengcs/client" +) // setupEnvironmentVariables converts a string array of environment variables // into a map as required by the HCS. Source array is in format [v1=k1] [v2=k2] etc. @@ -19,3 +23,16 @@ func setupEnvironmentVariables(a []string) map[string]string { func (s *LCOWOption) Apply(interface{}) error { return nil } + +// DebugGCS is a dirty hack for debugging for Linux Utility VMs. It simply +// runs a bunch of commands inside the UVM, but seriously aides in advanced debugging. +func (c *container) debugGCS() { + if c == nil || c.isWindows || c.hcsContainer == nil { + return + } + cfg := opengcs.Config{ + Uvm: c.hcsContainer, + UvmTimeoutSeconds: 600, + } + cfg.DebugGCS() +}