Merge pull request #1102 from dotcloud/1098-store_hostconfig_tmp
* Runtime: bind mounts are now preserved upon container restart
This commit is contained in:
commit
a909223ee2
28
container.go
28
container.go
|
@ -270,6 +270,26 @@ func (container *Container) ToDisk() (err error) {
|
||||||
return ioutil.WriteFile(container.jsonPath(), data, 0666)
|
return ioutil.WriteFile(container.jsonPath(), data, 0666)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (container *Container) ReadHostConfig() (*HostConfig, error) {
|
||||||
|
data, err := ioutil.ReadFile(container.hostConfigPath())
|
||||||
|
if err != nil {
|
||||||
|
return &HostConfig{}, err
|
||||||
|
}
|
||||||
|
hostConfig := &HostConfig{}
|
||||||
|
if err := json.Unmarshal(data, hostConfig); err != nil {
|
||||||
|
return &HostConfig{}, err
|
||||||
|
}
|
||||||
|
return hostConfig, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (container *Container) SaveHostConfig(hostConfig *HostConfig) (err error) {
|
||||||
|
data, err := json.Marshal(hostConfig)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return ioutil.WriteFile(container.hostConfigPath(), data, 0666)
|
||||||
|
}
|
||||||
|
|
||||||
func (container *Container) generateLXCConfig() error {
|
func (container *Container) generateLXCConfig() error {
|
||||||
fo, err := os.Create(container.lxcConfigPath())
|
fo, err := os.Create(container.lxcConfigPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -473,6 +493,9 @@ func (container *Container) Attach(stdin io.ReadCloser, stdinCloser io.Closer, s
|
||||||
func (container *Container) Start(hostConfig *HostConfig) error {
|
func (container *Container) Start(hostConfig *HostConfig) error {
|
||||||
container.State.Lock()
|
container.State.Lock()
|
||||||
defer container.State.Unlock()
|
defer container.State.Unlock()
|
||||||
|
if len(hostConfig.Binds) == 0 {
|
||||||
|
hostConfig, _ = container.ReadHostConfig()
|
||||||
|
}
|
||||||
|
|
||||||
if container.State.Running {
|
if container.State.Running {
|
||||||
return fmt.Errorf("The container %s is already running.", container.ID)
|
return fmt.Errorf("The container %s is already running.", container.ID)
|
||||||
|
@ -641,6 +664,7 @@ func (container *Container) Start(hostConfig *HostConfig) error {
|
||||||
container.waitLock = make(chan struct{})
|
container.waitLock = make(chan struct{})
|
||||||
|
|
||||||
container.ToDisk()
|
container.ToDisk()
|
||||||
|
container.SaveHostConfig(hostConfig)
|
||||||
go container.monitor()
|
go container.monitor()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -979,6 +1003,10 @@ func (container *Container) ReadLog(name string) (io.Reader, error) {
|
||||||
return os.Open(container.logPath(name))
|
return os.Open(container.logPath(name))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (container *Container) hostConfigPath() string {
|
||||||
|
return path.Join(container.root, "hostconfig.json")
|
||||||
|
}
|
||||||
|
|
||||||
func (container *Container) jsonPath() string {
|
func (container *Container) jsonPath() string {
|
||||||
return path.Join(container.root, "config.json")
|
return path.Join(container.root, "config.json")
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,7 +141,6 @@ func (runtime *Runtime) Register(container *Container) error {
|
||||||
utils.Debugf("Restarting")
|
utils.Debugf("Restarting")
|
||||||
container.State.Ghost = false
|
container.State.Ghost = false
|
||||||
container.State.setStopped(0)
|
container.State.setStopped(0)
|
||||||
// assume empty host config
|
|
||||||
hostConfig := &HostConfig{}
|
hostConfig := &HostConfig{}
|
||||||
if err := container.Start(hostConfig); err != nil {
|
if err := container.Start(hostConfig); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue