mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Ensure that all containers are stopped cleanly at shutdown
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
b4b87413d8
commit
f067e26367
1 changed files with 23 additions and 0 deletions
|
@ -778,8 +778,31 @@ func NewRuntimeFromDirectory(config *daemonconfig.Config, eng *engine.Engine) (*
|
||||||
return runtime, nil
|
return runtime, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (runtime *Runtime) shutdown() error {
|
||||||
|
group := sync.WaitGroup{}
|
||||||
|
utils.Debugf("starting clean shutdown of all containers...")
|
||||||
|
for _, container := range runtime.List() {
|
||||||
|
if container.State.IsRunning() {
|
||||||
|
utils.Debugf("stopping %s", container.ID)
|
||||||
|
group.Add(1)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer group.Done()
|
||||||
|
container.Stop(10)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
group.Wait()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (runtime *Runtime) Close() error {
|
func (runtime *Runtime) Close() error {
|
||||||
errorsStrings := []string{}
|
errorsStrings := []string{}
|
||||||
|
if err := runtime.shutdown(); err != nil {
|
||||||
|
utils.Errorf("runtime.shutdown(): %s", err)
|
||||||
|
errorsStrings = append(errorsStrings, err.Error())
|
||||||
|
}
|
||||||
if err := portallocator.ReleaseAll(); err != nil {
|
if err := portallocator.ReleaseAll(); err != nil {
|
||||||
utils.Errorf("portallocator.ReleaseAll(): %s", err)
|
utils.Errorf("portallocator.ReleaseAll(): %s", err)
|
||||||
errorsStrings = append(errorsStrings, err.Error())
|
errorsStrings = append(errorsStrings, err.Error())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue