simplify the runtime Register reconnect logic
Refactor the Register code a little bit to make it easier to comprehend.
This commit is contained in:
parent
457375ea37
commit
3cbec95177
27
runtime.go
27
runtime.go
|
@ -118,9 +118,6 @@ func (runtime *Runtime) Register(container *Container) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// init the wait lock
|
|
||||||
container.waitLock = make(chan struct{})
|
|
||||||
|
|
||||||
container.runtime = runtime
|
container.runtime = runtime
|
||||||
|
|
||||||
// Attach to stdout and stderr
|
// Attach to stdout and stderr
|
||||||
|
@ -136,10 +133,6 @@ func (runtime *Runtime) Register(container *Container) error {
|
||||||
runtime.containers.PushBack(container)
|
runtime.containers.PushBack(container)
|
||||||
runtime.idIndex.Add(container.ID)
|
runtime.idIndex.Add(container.ID)
|
||||||
|
|
||||||
// When we actually restart, Start() do the monitoring.
|
|
||||||
// However, when we simply 'reattach', we have to restart a monitor
|
|
||||||
nomonitor := false
|
|
||||||
|
|
||||||
// FIXME: if the container is supposed to be running but is not, auto restart it?
|
// FIXME: if the container is supposed to be running but is not, auto restart it?
|
||||||
// if so, then we need to restart monitor and init a new lock
|
// if so, then we need to restart monitor and init a new lock
|
||||||
// If the container is supposed to be running, make sure of it
|
// If the container is supposed to be running, make sure of it
|
||||||
|
@ -157,7 +150,6 @@ func (runtime *Runtime) Register(container *Container) error {
|
||||||
if err := container.Start(); err != nil {
|
if err := container.Start(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
nomonitor = true
|
|
||||||
} else {
|
} else {
|
||||||
utils.Debugf("Marking as stopped")
|
utils.Debugf("Marking as stopped")
|
||||||
container.State.setStopped(-127)
|
container.State.setStopped(-127)
|
||||||
|
@ -165,16 +157,17 @@ func (runtime *Runtime) Register(container *Container) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
}
|
utils.Debugf("Reconnecting to container %v", container.ID)
|
||||||
|
|
||||||
// If the container is not running or just has been flagged not running
|
if err := container.allocateNetwork(); err != nil {
|
||||||
// then close the wait lock chan (will be reset upon start)
|
return err
|
||||||
if !container.State.Running {
|
}
|
||||||
close(container.waitLock)
|
|
||||||
} else if !nomonitor {
|
container.waitLock = make(chan struct{})
|
||||||
container.allocateNetwork()
|
|
||||||
go container.monitor()
|
go container.monitor()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue