mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Optimize the restart function code
Signed-off-by: zhouhao <zhouhao@cn.fujitsu.com>
This commit is contained in:
parent
25587906d1
commit
870cf1096f
1 changed files with 18 additions and 16 deletions
|
@ -36,25 +36,27 @@ func (daemon *Daemon) containerRestart(container *container.Container, seconds i
|
||||||
defer daemon.Unmount(container)
|
defer daemon.Unmount(container)
|
||||||
}
|
}
|
||||||
|
|
||||||
// set AutoRemove flag to false before stop so the container won't be
|
if container.IsRunning() {
|
||||||
// removed during restart process
|
// set AutoRemove flag to false before stop so the container won't be
|
||||||
autoRemove := container.HostConfig.AutoRemove
|
// removed during restart process
|
||||||
|
autoRemove := container.HostConfig.AutoRemove
|
||||||
|
|
||||||
container.HostConfig.AutoRemove = false
|
container.HostConfig.AutoRemove = false
|
||||||
err := daemon.containerStop(container, seconds)
|
err := daemon.containerStop(container, seconds)
|
||||||
// restore AutoRemove irrespective of whether the stop worked or not
|
// restore AutoRemove irrespective of whether the stop worked or not
|
||||||
container.HostConfig.AutoRemove = autoRemove
|
container.HostConfig.AutoRemove = autoRemove
|
||||||
// containerStop will write HostConfig to disk, we shall restore AutoRemove
|
// containerStop will write HostConfig to disk, we shall restore AutoRemove
|
||||||
// in disk too
|
// in disk too
|
||||||
if toDiskErr := container.ToDiskLocking(); toDiskErr != nil {
|
if toDiskErr := container.ToDiskLocking(); toDiskErr != nil {
|
||||||
logrus.Errorf("Write container to disk error: %v", toDiskErr)
|
logrus.Errorf("Write container to disk error: %v", toDiskErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err := daemon.containerStart(container); err != nil {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = daemon.containerStart(container); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue