mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
store hostConfig to /tmp while container is running
This commit is contained in:
parent
8f9dd86146
commit
06b53e3fc7
2 changed files with 33 additions and 1 deletions
30
container.go
30
container.go
|
@ -265,6 +265,29 @@ func (container *Container) ToDisk() (err error) {
|
||||||
return ioutil.WriteFile(container.jsonPath(), data, 0666)
|
return ioutil.WriteFile(container.jsonPath(), data, 0666)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (container *Container) ReadTempHostConfig() (*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) {
|
||||||
|
if hostConfig == nil {
|
||||||
|
return os.Remove(container.hostConfigPath())
|
||||||
|
}
|
||||||
|
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 {
|
||||||
|
@ -636,6 +659,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
|
||||||
}
|
}
|
||||||
|
@ -791,6 +815,8 @@ func (container *Container) monitor() {
|
||||||
// FIXME: why are we serializing running state to disk in the first place?
|
// FIXME: why are we serializing running state to disk in the first place?
|
||||||
//log.Printf("%s: Failed to dump configuration to the disk: %s", container.ID, err)
|
//log.Printf("%s: Failed to dump configuration to the disk: %s", container.ID, err)
|
||||||
}
|
}
|
||||||
|
// Remove temp host config
|
||||||
|
container.SaveHostConfig(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) kill() error {
|
func (container *Container) kill() error {
|
||||||
|
@ -970,6 +996,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("/tmp", container.ID+".config.host")
|
||||||
|
}
|
||||||
|
|
||||||
func (container *Container) jsonPath() string {
|
func (container *Container) jsonPath() string {
|
||||||
return path.Join(container.root, "config.json")
|
return path.Join(container.root, "config.json")
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,7 +145,7 @@ func (runtime *Runtime) Register(container *Container) error {
|
||||||
container.State.Ghost = false
|
container.State.Ghost = false
|
||||||
container.State.setStopped(0)
|
container.State.setStopped(0)
|
||||||
// assume empty host config
|
// assume empty host config
|
||||||
hostConfig := &HostConfig{}
|
hostConfig, _ := container.ReadTempHostConfig()
|
||||||
if err := container.Start(hostConfig); err != nil {
|
if err := container.Start(hostConfig); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -156,6 +156,8 @@ func (runtime *Runtime) Register(container *Container) error {
|
||||||
if err := container.ToDisk(); err != nil {
|
if err := container.ToDisk(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// remove temp host config
|
||||||
|
container.SaveHostConfig(nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue