| ... | ... |
@@ -265,6 +265,29 @@ func (container *Container) ToDisk() (err error) {
|
| 265 | 265 |
return ioutil.WriteFile(container.jsonPath(), data, 0666) |
| 266 | 266 |
} |
| 267 | 267 |
|
| 268 |
+func (container *Container) ReadTempHostConfig() (*HostConfig, error) {
|
|
| 269 |
+ data, err := ioutil.ReadFile(container.hostConfigPath()) |
|
| 270 |
+ if err != nil {
|
|
| 271 |
+ return &HostConfig{}, err
|
|
| 272 |
+ } |
|
| 273 |
+ hostConfig := &HostConfig{}
|
|
| 274 |
+ if err := json.Unmarshal(data, hostConfig); err != nil {
|
|
| 275 |
+ return &HostConfig{}, err
|
|
| 276 |
+ } |
|
| 277 |
+ return hostConfig, nil |
|
| 278 |
+} |
|
| 279 |
+ |
|
| 280 |
+func (container *Container) SaveHostConfig(hostConfig *HostConfig) (err error) {
|
|
| 281 |
+ if hostConfig == nil {
|
|
| 282 |
+ return os.Remove(container.hostConfigPath()) |
|
| 283 |
+ } |
|
| 284 |
+ data, err := json.Marshal(hostConfig) |
|
| 285 |
+ if err != nil {
|
|
| 286 |
+ return |
|
| 287 |
+ } |
|
| 288 |
+ return ioutil.WriteFile(container.hostConfigPath(), data, 0666) |
|
| 289 |
+} |
|
| 290 |
+ |
|
| 268 | 291 |
func (container *Container) generateLXCConfig() error {
|
| 269 | 292 |
fo, err := os.Create(container.lxcConfigPath()) |
| 270 | 293 |
if err != nil {
|
| ... | ... |
@@ -636,6 +659,7 @@ func (container *Container) Start(hostConfig *HostConfig) error {
|
| 636 | 636 |
container.waitLock = make(chan struct{})
|
| 637 | 637 |
|
| 638 | 638 |
container.ToDisk() |
| 639 |
+ container.SaveHostConfig(hostConfig) |
|
| 639 | 640 |
go container.monitor() |
| 640 | 641 |
return nil |
| 641 | 642 |
} |
| ... | ... |
@@ -791,6 +815,8 @@ func (container *Container) monitor() {
|
| 791 | 791 |
// FIXME: why are we serializing running state to disk in the first place? |
| 792 | 792 |
//log.Printf("%s: Failed to dump configuration to the disk: %s", container.ID, err)
|
| 793 | 793 |
} |
| 794 |
+ // Remove temp host config |
|
| 795 |
+ container.SaveHostConfig(nil) |
|
| 794 | 796 |
} |
| 795 | 797 |
|
| 796 | 798 |
func (container *Container) kill() error {
|
| ... | ... |
@@ -970,6 +996,10 @@ func (container *Container) ReadLog(name string) (io.Reader, error) {
|
| 970 | 970 |
return os.Open(container.logPath(name)) |
| 971 | 971 |
} |
| 972 | 972 |
|
| 973 |
+func (container *Container) hostConfigPath() string {
|
|
| 974 |
+ return path.Join("/tmp", container.ID+".config.host")
|
|
| 975 |
+} |
|
| 976 |
+ |
|
| 973 | 977 |
func (container *Container) jsonPath() string {
|
| 974 | 978 |
return path.Join(container.root, "config.json") |
| 975 | 979 |
} |
| ... | ... |
@@ -145,7 +145,7 @@ func (runtime *Runtime) Register(container *Container) error {
|
| 145 | 145 |
container.State.Ghost = false |
| 146 | 146 |
container.State.setStopped(0) |
| 147 | 147 |
// assume empty host config |
| 148 |
- hostConfig := &HostConfig{}
|
|
| 148 |
+ hostConfig, _ := container.ReadTempHostConfig() |
|
| 149 | 149 |
if err := container.Start(hostConfig); err != nil {
|
| 150 | 150 |
return err |
| 151 | 151 |
} |
| ... | ... |
@@ -156,6 +156,8 @@ func (runtime *Runtime) Register(container *Container) error {
|
| 156 | 156 |
if err := container.ToDisk(); err != nil {
|
| 157 | 157 |
return err |
| 158 | 158 |
} |
| 159 |
+ // remove temp host config |
|
| 160 |
+ container.SaveHostConfig(nil) |
|
| 159 | 161 |
} |
| 160 | 162 |
} |
| 161 | 163 |
} |