... | ... |
@@ -136,14 +136,14 @@ func (runtime *Runtime) Register(container *Container) error { |
136 | 136 |
} |
137 | 137 |
|
138 | 138 |
// FIXME: if the container is supposed to be running but is not, auto restart it? |
139 |
- // If the container is supposed to be running, make sure of if |
|
139 |
+ // If the container is supposed to be running, make sure of it |
|
140 | 140 |
if container.State.Running { |
141 | 141 |
if output, err := exec.Command("lxc-info", "-n", container.Id).CombinedOutput(); err != nil { |
142 | 142 |
return err |
143 | 143 |
} else { |
144 | 144 |
if !strings.Contains(string(output), "RUNNING") { |
145 | 145 |
Debugf("Container %s was supposed to be running be is not.", container.Id) |
146 |
- container.State.Running = false |
|
146 |
+ container.State.setStopped(-127) |
|
147 | 147 |
if err := container.ToDisk(); err != nil { |
148 | 148 |
return err |
149 | 149 |
} |
... | ... |
@@ -297,10 +297,15 @@ func TestRestore(t *testing.T) { |
297 | 297 |
t.Fatal(err) |
298 | 298 |
} |
299 | 299 |
|
300 |
+ if !container1_1.State.Running { |
|
301 |
+ t.Fatalf("Container %v should appear as running but isn't", container1_1.Id) |
|
302 |
+ } |
|
303 |
+ |
|
300 | 304 |
// Simulate a crash/manual quit of dockerd: process dies, states stays 'Running' |
301 |
- if err := exec.Command("lxc-kill", "-n", container1_1.Id, "9").Run(); err == nil { |
|
302 |
- t.Fatalf("container supposed to be killed (return error 255). Success received.") |
|
305 |
+ if err := container1_1.Stop(); err != nil { |
|
306 |
+ t.Fatalf("Could not stop container: %v", err) |
|
303 | 307 |
} |
308 |
+ |
|
304 | 309 |
container1_1.State.Running = true |
305 | 310 |
|
306 | 311 |
if len(runtime1.List()) != 2 { |
... | ... |
@@ -310,6 +315,10 @@ func TestRestore(t *testing.T) { |
310 | 310 |
t.Fatal(err) |
311 | 311 |
} |
312 | 312 |
|
313 |
+ if !container1_1.State.Running { |
|
314 |
+ t.Fatalf("Container %v should appear as running but isn't", container1_1.Id) |
|
315 |
+ } |
|
316 |
+ |
|
313 | 317 |
// Here are are simulating a docker restart - that is, reloading all containers |
314 | 318 |
// from scratch |
315 | 319 |
runtime2, err := NewRuntimeFromDirectory(root) |
... | ... |
@@ -323,6 +332,7 @@ func TestRestore(t *testing.T) { |
323 | 323 |
runningCount := 0 |
324 | 324 |
for _, c := range runtime2.List() { |
325 | 325 |
if c.State.Running { |
326 |
+ t.Errorf("Running container found: %v (%v)", c.Id, c.Path) |
|
326 | 327 |
runningCount++ |
327 | 328 |
} |
328 | 329 |
} |