container.Register() checks both IsRunning() and IsGhost(), but at
this point IsGhost() is always true if IsRunning() is true. For a
newly created container both are false, and for a restored-from-disk
container Daemon.load() sets Ghost to true if IsRunning is true. So we
just drop the IsGhost check.
This was the last call to IsGhost, so we remove It and all other
traces of the ghost state.
Docker-DCO-1.1-Signed-off-by: Alexander Larsson <alexl@redhat.com> (github: alexlarsson)
| ... | ... |
@@ -134,9 +134,6 @@ func (daemon *Daemon) load(id string) (*Container, error) {
|
| 134 | 134 |
if container.ID != id {
|
| 135 | 135 |
return container, fmt.Errorf("Container %s is stored at %s", container.ID, id)
|
| 136 | 136 |
} |
| 137 |
- if container.State.IsRunning() {
|
|
| 138 |
- container.State.SetGhost(true) |
|
| 139 |
- } |
|
| 140 | 137 |
return container, nil |
| 141 | 138 |
} |
| 142 | 139 |
|
| ... | ... |
@@ -171,35 +168,32 @@ func (daemon *Daemon) Register(container *Container) error {
|
| 171 | 171 |
// if so, then we need to restart monitor and init a new lock |
| 172 | 172 |
// If the container is supposed to be running, make sure of it |
| 173 | 173 |
if container.State.IsRunning() {
|
| 174 |
- if container.State.IsGhost() {
|
|
| 175 |
- utils.Debugf("killing ghost %s", container.ID)
|
|
| 174 |
+ utils.Debugf("killing old running container %s", container.ID)
|
|
| 176 | 175 |
|
| 177 |
- existingPid := container.State.Pid |
|
| 178 |
- container.State.SetGhost(false) |
|
| 179 |
- container.State.SetStopped(0) |
|
| 176 |
+ existingPid := container.State.Pid |
|
| 177 |
+ container.State.SetStopped(0) |
|
| 180 | 178 |
|
| 181 |
- // We only have to handle this for lxc because the other drivers will ensure that |
|
| 182 |
- // no ghost processes are left when docker dies |
|
| 183 |
- if container.ExecDriver == "" || strings.Contains(container.ExecDriver, "lxc") {
|
|
| 184 |
- lxc.KillLxc(container.ID, 9) |
|
| 185 |
- } else {
|
|
| 186 |
- // use the current driver and ensure that the container is dead x.x |
|
| 187 |
- cmd := &execdriver.Command{
|
|
| 188 |
- ID: container.ID, |
|
| 189 |
- } |
|
| 190 |
- var err error |
|
| 191 |
- cmd.Process, err = os.FindProcess(existingPid) |
|
| 192 |
- if err != nil {
|
|
| 193 |
- utils.Debugf("cannot find existing process for %d", existingPid)
|
|
| 194 |
- } |
|
| 195 |
- daemon.execDriver.Terminate(cmd) |
|
| 196 |
- } |
|
| 197 |
- if err := container.Unmount(); err != nil {
|
|
| 198 |
- utils.Debugf("ghost unmount error %s", err)
|
|
| 179 |
+ // We only have to handle this for lxc because the other drivers will ensure that |
|
| 180 |
+ // no processes are left when docker dies |
|
| 181 |
+ if container.ExecDriver == "" || strings.Contains(container.ExecDriver, "lxc") {
|
|
| 182 |
+ lxc.KillLxc(container.ID, 9) |
|
| 183 |
+ } else {
|
|
| 184 |
+ // use the current driver and ensure that the container is dead x.x |
|
| 185 |
+ cmd := &execdriver.Command{
|
|
| 186 |
+ ID: container.ID, |
|
| 199 | 187 |
} |
| 200 |
- if err := container.ToDisk(); err != nil {
|
|
| 201 |
- utils.Debugf("saving ghost state to disk %s", err)
|
|
| 188 |
+ var err error |
|
| 189 |
+ cmd.Process, err = os.FindProcess(existingPid) |
|
| 190 |
+ if err != nil {
|
|
| 191 |
+ utils.Debugf("cannot find existing process for %d", existingPid)
|
|
| 202 | 192 |
} |
| 193 |
+ daemon.execDriver.Terminate(cmd) |
|
| 194 |
+ } |
|
| 195 |
+ if err := container.Unmount(); err != nil {
|
|
| 196 |
+ utils.Debugf("unmount error %s", err)
|
|
| 197 |
+ } |
|
| 198 |
+ if err := container.ToDisk(); err != nil {
|
|
| 199 |
+ utils.Debugf("saving stopped state to disk %s", err)
|
|
| 203 | 200 |
} |
| 204 | 201 |
|
| 205 | 202 |
info := daemon.execDriver.Info(container.ID) |
| ... | ... |
@@ -211,8 +205,6 @@ func (daemon *Daemon) Register(container *Container) error {
|
| 211 | 211 |
utils.Debugf("restart unmount error %s", err)
|
| 212 | 212 |
} |
| 213 | 213 |
|
| 214 |
- container.State.SetGhost(false) |
|
| 215 |
- container.State.SetStopped(0) |
|
| 216 | 214 |
if err := container.Start(); err != nil {
|
| 217 | 215 |
return err |
| 218 | 216 |
} |
| ... | ... |
@@ -14,7 +14,6 @@ type State struct {
|
| 14 | 14 |
ExitCode int |
| 15 | 15 |
StartedAt time.Time |
| 16 | 16 |
FinishedAt time.Time |
| 17 |
- Ghost bool |
|
| 18 | 17 |
} |
| 19 | 18 |
|
| 20 | 19 |
// String returns a human-readable description of the state |
| ... | ... |
@@ -23,9 +22,6 @@ func (s *State) String() string {
|
| 23 | 23 |
defer s.RUnlock() |
| 24 | 24 |
|
| 25 | 25 |
if s.Running {
|
| 26 |
- if s.Ghost {
|
|
| 27 |
- return fmt.Sprintf("Ghost")
|
|
| 28 |
- } |
|
| 29 | 26 |
return fmt.Sprintf("Up %s", utils.HumanDuration(time.Now().UTC().Sub(s.StartedAt)))
|
| 30 | 27 |
} |
| 31 | 28 |
if s.FinishedAt.IsZero() {
|
| ... | ... |
@@ -41,13 +37,6 @@ func (s *State) IsRunning() bool {
|
| 41 | 41 |
return s.Running |
| 42 | 42 |
} |
| 43 | 43 |
|
| 44 |
-func (s *State) IsGhost() bool {
|
|
| 45 |
- s.RLock() |
|
| 46 |
- defer s.RUnlock() |
|
| 47 |
- |
|
| 48 |
- return s.Ghost |
|
| 49 |
-} |
|
| 50 |
- |
|
| 51 | 44 |
func (s *State) GetExitCode() int {
|
| 52 | 45 |
s.RLock() |
| 53 | 46 |
defer s.RUnlock() |
| ... | ... |
@@ -55,19 +44,11 @@ func (s *State) GetExitCode() int {
|
| 55 | 55 |
return s.ExitCode |
| 56 | 56 |
} |
| 57 | 57 |
|
| 58 |
-func (s *State) SetGhost(val bool) {
|
|
| 59 |
- s.Lock() |
|
| 60 |
- defer s.Unlock() |
|
| 61 |
- |
|
| 62 |
- s.Ghost = val |
|
| 63 |
-} |
|
| 64 |
- |
|
| 65 | 58 |
func (s *State) SetRunning(pid int) {
|
| 66 | 59 |
s.Lock() |
| 67 | 60 |
defer s.Unlock() |
| 68 | 61 |
|
| 69 | 62 |
s.Running = true |
| 70 |
- s.Ghost = false |
|
| 71 | 63 |
s.ExitCode = 0 |
| 72 | 64 |
s.Pid = pid |
| 73 | 65 |
s.StartedAt = time.Now().UTC() |