Merge pull request #26005 from q384566678/branch-test

Optimize the restart function code
This commit is contained in:
Michael Crosby 2016-08-26 15:14:49 -07:00 committed by GitHub
commit 07328cf3f6
1 changed files with 18 additions and 16 deletions

View File

@ -36,25 +36,27 @@ func (daemon *Daemon) containerRestart(container *container.Container, seconds i
defer daemon.Unmount(container)
}
// set AutoRemove flag to false before stop so the container won't be
// removed during restart process
autoRemove := container.HostConfig.AutoRemove
if container.IsRunning() {
// set AutoRemove flag to false before stop so the container won't be
// removed during restart process
autoRemove := container.HostConfig.AutoRemove
container.HostConfig.AutoRemove = false
err := daemon.containerStop(container, seconds)
// restore AutoRemove irrespective of whether the stop worked or not
container.HostConfig.AutoRemove = autoRemove
// containerStop will write HostConfig to disk, we shall restore AutoRemove
// in disk too
if toDiskErr := container.ToDiskLocking(); toDiskErr != nil {
logrus.Errorf("Write container to disk error: %v", toDiskErr)
container.HostConfig.AutoRemove = false
err := daemon.containerStop(container, seconds)
// restore AutoRemove irrespective of whether the stop worked or not
container.HostConfig.AutoRemove = autoRemove
// containerStop will write HostConfig to disk, we shall restore AutoRemove
// in disk too
if toDiskErr := container.ToDiskLocking(); toDiskErr != nil {
logrus.Errorf("Write container to disk error: %v", toDiskErr)
}
if err != nil {
return err
}
}
if err != nil {
return err
}
if err = daemon.containerStart(container); err != nil {
if err := daemon.containerStart(container); err != nil {
return err
}