server: restore containers state from disk on startup
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
da0b8a6157
commit
a41ca975c1
2 changed files with 34 additions and 9 deletions
|
@ -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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue