From 7a3f7b9a29cf056716318d2cde18d4546d48ee77 Mon Sep 17 00:00:00 2001 From: Victor Marmol Date: Fri, 25 Jul 2014 08:20:07 -0700 Subject: [PATCH] Return an empty state for old versions of Docker. Fixes #127. --- container/docker/handler.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/container/docker/handler.go b/container/docker/handler.go index 8453d031..2e8662ad 100644 --- a/container/docker/handler.go +++ b/container/docker/handler.go @@ -18,6 +18,7 @@ import ( "encoding/json" "errors" "fmt" + "log" "math" "os" "path" @@ -119,6 +120,14 @@ func (self *dockerContainerHandler) readLibcontainerConfig() (config *libcontain func (self *dockerContainerHandler) readLibcontainerState() (state *libcontainer.State, err error) { statePath := path.Join(dockerRootDir, self.id, "state.json") if !utils.FileExists(statePath) { + // TODO(vmarmol): Remove this once we can depend on a newer Docker. + // Libcontainer changed how its state was stored, try the old way of a "pid" file + if utils.FileExists(path.Join(dockerRootDir, self.id, "pid")) { + // We don't need the old state, return an empty state and we'll gracefully degrade. + state = new(libcontainer.State) + return + } + // TODO(vishh): Return file name as well once we have a better error interface. err = fileNotFound return @@ -190,6 +199,7 @@ func (self *dockerContainerHandler) GetStats() (stats *info.ContainerStats, err config, err := self.readLibcontainerConfig() if err != nil { if err == fileNotFound { + log.Printf("Libcontainer config not found for container %q", self.name) return &info.ContainerStats{}, nil } return @@ -197,6 +207,7 @@ func (self *dockerContainerHandler) GetStats() (stats *info.ContainerStats, err state, err := self.readLibcontainerState() if err != nil { if err == fileNotFound { + log.Printf("Libcontainer state not found for container %q", self.name) return &info.ContainerStats{}, nil } return