Browse code

Ensure state is destroyed on daemont restart

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>

Michael Crosby authored on 2015/04/16 09:39:34
Showing 2 changed files
... ...
@@ -273,19 +273,8 @@ func (daemon *Daemon) register(container *Container, updateSuffixarray bool) err
273 273
 		if err := container.ToDisk(); err != nil {
274 274
 			logrus.Debugf("saving stopped state to disk %s", err)
275 275
 		}
276
-
277
-		info := daemon.execDriver.Info(container.ID)
278
-		if !info.IsRunning() {
279
-			logrus.Debugf("Container %s was supposed to be running but is not.", container.ID)
280
-
281
-			logrus.Debug("Marking as stopped")
282
-
283
-			container.SetStopped(&execdriver.ExitStatus{ExitCode: -127})
284
-			if err := container.ToDisk(); err != nil {
285
-				return err
286
-			}
287
-		}
288 276
 	}
277
+
289 278
 	return nil
290 279
 }
291 280
 
... ...
@@ -268,29 +268,25 @@ func (d *driver) Unpause(c *execdriver.Command) error {
268 268
 
269 269
 func (d *driver) Terminate(c *execdriver.Command) error {
270 270
 	defer d.cleanContainer(c.ID)
271
-	// lets check the start time for the process
272
-	active := d.activeContainers[c.ID]
273
-	if active == nil {
274
-		return fmt.Errorf("active container for %s does not exist", c.ID)
271
+	container, err := d.factory.Load(c.ID)
272
+	if err != nil {
273
+		return err
275 274
 	}
276
-	state, err := active.State()
275
+	defer container.Destroy()
276
+	state, err := container.State()
277 277
 	if err != nil {
278 278
 		return err
279 279
 	}
280 280
 	pid := state.InitProcessPid
281
-
282 281
 	currentStartTime, err := system.GetProcessStartTime(pid)
283 282
 	if err != nil {
284 283
 		return err
285 284
 	}
286
-
287 285
 	if state.InitProcessStartTime == currentStartTime {
288 286
 		err = syscall.Kill(pid, 9)
289 287
 		syscall.Wait4(pid, nil, 0, nil)
290 288
 	}
291
-
292 289
 	return err
293
-
294 290
 }
295 291
 
296 292
 func (d *driver) Info(id string) execdriver.Info {