From c36cca18b40acba589566caffbbf4851c7e6569f Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Thu, 11 Apr 2013 09:26:17 -0700 Subject: [PATCH] Detect and mark ghost container. Upstream-commit: 313d13ea01f58c3e611fb85e435d36dd4907a6ac Component: engine --- components/engine/container.go | 9 +++++++++ components/engine/runtime.go | 3 +++ components/engine/state.go | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/components/engine/container.go b/components/engine/container.go index f180c7559b..eefbbe5c74 100644 --- a/components/engine/container.go +++ b/components/engine/container.go @@ -561,6 +561,12 @@ func (container *Container) kill() error { func (container *Container) Kill() error { container.State.lock() 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() } @@ -570,6 +576,9 @@ func (container *Container) Stop() error { if !container.State.Running { return nil } + if container.State.Ghost { + return fmt.Errorf("Impossible to stop ghost containers") + } // 1. Send a SIGTERM if output, err := exec.Command("lxc-kill", "-n", container.Id, "15").CombinedOutput(); err != nil { diff --git a/components/engine/runtime.go b/components/engine/runtime.go index 24194f74ad..ec02939702 100644 --- a/components/engine/runtime.go +++ b/components/engine/runtime.go @@ -119,6 +119,9 @@ func (runtime *Runtime) Load(id string) (*Container, error) { if 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 { return nil, err } diff --git a/components/engine/state.go b/components/engine/state.go index 2ca7130921..f09b289a6a 100644 --- a/components/engine/state.go +++ b/components/engine/state.go @@ -12,11 +12,15 @@ type State struct { ExitCode int StartedAt time.Time l *sync.Mutex + Ghost bool } // String returns a human-readable description of the state func (s *State) String() string { 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("Exit %d", s.ExitCode)