mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Detect and mark ghost container.
This commit is contained in:
parent
c902c43766
commit
313d13ea01
3 changed files with 16 additions and 0 deletions
|
@ -561,6 +561,12 @@ func (container *Container) kill() error {
|
||||||
func (container *Container) Kill() error {
|
func (container *Container) Kill() error {
|
||||||
container.State.lock()
|
container.State.lock()
|
||||||
defer container.State.unlock()
|
defer container.State.unlock()
|
||||||
|
if !container.State.Running {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if container.State.Ghost {
|
||||||
|
return fmt.Errorf("Impossible to kill ghost containers")
|
||||||
|
}
|
||||||
return container.kill()
|
return container.kill()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -570,6 +576,9 @@ func (container *Container) Stop() error {
|
||||||
if !container.State.Running {
|
if !container.State.Running {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if container.State.Ghost {
|
||||||
|
return fmt.Errorf("Impossible to stop ghost containers")
|
||||||
|
}
|
||||||
|
|
||||||
// 1. Send a SIGTERM
|
// 1. Send a SIGTERM
|
||||||
if output, err := exec.Command("lxc-kill", "-n", container.Id, "15").CombinedOutput(); err != nil {
|
if output, err := exec.Command("lxc-kill", "-n", container.Id, "15").CombinedOutput(); err != nil {
|
||||||
|
|
|
@ -119,6 +119,9 @@ func (runtime *Runtime) Load(id string) (*Container, error) {
|
||||||
if container.Id != id {
|
if container.Id != id {
|
||||||
return container, fmt.Errorf("Container %s is stored at %s", container.Id, id)
|
return container, fmt.Errorf("Container %s is stored at %s", container.Id, id)
|
||||||
}
|
}
|
||||||
|
if container.State.Running {
|
||||||
|
container.State.Ghost = true
|
||||||
|
}
|
||||||
if err := runtime.Register(container); err != nil {
|
if err := runtime.Register(container); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
4
state.go
4
state.go
|
@ -12,11 +12,15 @@ type State struct {
|
||||||
ExitCode int
|
ExitCode int
|
||||||
StartedAt time.Time
|
StartedAt time.Time
|
||||||
l *sync.Mutex
|
l *sync.Mutex
|
||||||
|
Ghost bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// String returns a human-readable description of the state
|
// String returns a human-readable description of the state
|
||||||
func (s *State) String() string {
|
func (s *State) String() string {
|
||||||
if s.Running {
|
if s.Running {
|
||||||
|
if s.Ghost {
|
||||||
|
return fmt.Sprintf("Running ghost")
|
||||||
|
}
|
||||||
return fmt.Sprintf("Up %s", HumanDuration(time.Now().Sub(s.StartedAt)))
|
return fmt.Sprintf("Up %s", HumanDuration(time.Now().Sub(s.StartedAt)))
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("Exit %d", s.ExitCode)
|
return fmt.Sprintf("Exit %d", s.ExitCode)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue