Fixed a bug which caused docker to crash at startup while restoring existing containers
This commit is contained in:
parent
c59fff422f
commit
4474cd5677
3 changed files with 14 additions and 7 deletions
10
container.go
10
container.go
|
@ -100,17 +100,25 @@ func createContainer(id string, root string, command string, args []string, imag
|
|||
return container, nil
|
||||
}
|
||||
|
||||
func loadContainer(containerPath string) (*Container, error) {
|
||||
func loadContainer(store *fs.Store, containerPath string) (*Container, error) {
|
||||
data, err := ioutil.ReadFile(path.Join(containerPath, "config.json"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mountpoint, err := store.FetchMountpoint(
|
||||
path.Join(containerPath, "rootfs"),
|
||||
path.Join(containerPath, "rw"),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
container := &Container{
|
||||
stdout: newWriteBroadcaster(),
|
||||
stderr: newWriteBroadcaster(),
|
||||
stdoutLog: new(bytes.Buffer),
|
||||
stderrLog: new(bytes.Buffer),
|
||||
lxcConfigPath: path.Join(containerPath, "config.lxc"),
|
||||
Mountpoint: mountpoint,
|
||||
}
|
||||
if err := json.Unmarshal(data, container); err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -92,12 +92,11 @@ func (docker *Docker) restore() error {
|
|||
return err
|
||||
}
|
||||
for _, v := range dir {
|
||||
container, err := loadContainer(path.Join(docker.repository, v.Name()))
|
||||
container, err := loadContainer(docker.Store, path.Join(docker.repository, v.Name()))
|
||||
if err != nil {
|
||||
log.Printf("Failed to load container %v: %v", v.Name(), err)
|
||||
continue
|
||||
}
|
||||
container.Mountpoint.Store = docker.Store
|
||||
docker.containers.PushBack(container)
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -227,7 +227,7 @@ func (image *Image) Mountpoints() ([]*Mountpoint, error) {
|
|||
|
||||
func (image *Image) Mount(root, rw string) (*Mountpoint, error) {
|
||||
var mountpoint *Mountpoint
|
||||
if mp, err := image.fetchMountpoint(root, rw); err != nil {
|
||||
if mp, err := image.store.FetchMountpoint(root, rw); err != nil {
|
||||
return nil, err
|
||||
} else if mp == nil {
|
||||
mountpoint, err = image.Mountpoint(root, rw)
|
||||
|
@ -345,8 +345,8 @@ func (mp *Mountpoint) Deregister() error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (image *Image) fetchMountpoint(root, rw string) (*Mountpoint, error) {
|
||||
res, err := image.store.orm.Select(Mountpoint{}, "select * from mountpoints where Image=? and Root=? and Rw=?", image.Id, root, rw)
|
||||
func (store *Store) FetchMountpoint(root, rw string) (*Mountpoint, error) {
|
||||
res, err := store.orm.Select(Mountpoint{}, "select * from mountpoints where Root=? and Rw=?", root, rw)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if len(res) < 1 || res[0] == nil {
|
||||
|
@ -354,7 +354,7 @@ func (image *Image) fetchMountpoint(root, rw string) (*Mountpoint, error) {
|
|||
}
|
||||
|
||||
mp := res[0].(*Mountpoint)
|
||||
mp.Store = image.store
|
||||
mp.Store = store
|
||||
return mp, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue