... | ... |
@@ -7,8 +7,10 @@ import ( |
7 | 7 |
"io" |
8 | 8 |
"io/ioutil" |
9 | 9 |
"os" |
10 |
+ "os/exec" |
|
10 | 11 |
"path" |
11 | 12 |
"sort" |
13 |
+ "strings" |
|
12 | 14 |
"sync" |
13 | 15 |
"time" |
14 | 16 |
) |
... | ... |
@@ -132,6 +134,23 @@ func (runtime *Runtime) Register(container *Container) error { |
132 | 132 |
if err := validateId(container.Id); err != nil { |
133 | 133 |
return err |
134 | 134 |
} |
135 |
+ |
|
136 |
+ // FIXME: if the container is supposed to be running but is not, auto restart it? |
|
137 |
+ // If the container is supposed to be running, make sure of if |
|
138 |
+ if container.State.Running { |
|
139 |
+ if output, err := exec.Command("lxc-info", "-n", container.Id).CombinedOutput(); err != nil { |
|
140 |
+ return err |
|
141 |
+ } else { |
|
142 |
+ if !strings.Contains(string(output), "RUNNING") { |
|
143 |
+ Debugf("Container %s was supposed to be running be is not.", container.Id) |
|
144 |
+ container.State.Running = false |
|
145 |
+ if err := container.ToDisk(); err != nil { |
|
146 |
+ return err |
|
147 |
+ } |
|
148 |
+ } |
|
149 |
+ } |
|
150 |
+ } |
|
151 |
+ |
|
135 | 152 |
container.runtime = runtime |
136 | 153 |
// Setup state lock (formerly in newState() |
137 | 154 |
lock := new(sync.Mutex) |
... | ... |
@@ -259,7 +278,6 @@ func NewRuntimeFromDirectory(root string) (*Runtime, error) { |
259 | 259 |
// If the auth file does not exist, keep going |
260 | 260 |
return nil, err |
261 | 261 |
} |
262 |
- |
|
263 | 262 |
runtime := &Runtime{ |
264 | 263 |
root: root, |
265 | 264 |
repository: runtimeRepo, |