Skip to content

Commit

Permalink
Return an empty state for old versions of Docker.
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarmol committed Jul 25, 2014
1 parent 02b06ea commit 7a3f7b9
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions container/docker/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"math"
"os"
"path"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -190,13 +199,15 @@ 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
}
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
Expand Down

0 comments on commit 7a3f7b9

Please sign in to comment.