server: restore containers state from disk on startup

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2017-05-11 12:10:18 +02:00
parent da0b8a6157
commit a41ca975c1
No known key found for this signature in database
GPG key ID: B2BEAD150DE936B9
2 changed files with 34 additions and 9 deletions

View file

@ -1,7 +1,9 @@
package oci
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"sync"
"time"
@ -65,6 +67,18 @@ func NewContainer(id string, name string, bundlePath string, logPath string, net
return c, nil
}
// FromDisk restores container's state from disk
func (c *Container) FromDisk() error {
jsonSource, err := os.Open(c.StatePath())
if err != nil {
return err
}
defer jsonSource.Close()
dec := json.NewDecoder(jsonSource)
return dec.Decode(c.state)
}
// StatePath returns the containers state.json path
func (c *Container) StatePath() string {
return filepath.Join(c.dir, "state.json")