2014-06-05 07:46:30 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2014-06-10 23:14:16 +08:00
|
|
|
"github.com/docker/libcontainer"
|
2014-06-05 07:46:30 +08:00
|
|
|
)
|
|
|
|
|
2014-06-24 07:54:35 +08:00
|
|
|
func loadContainer() (*libcontainer.Config, error) {
|
2014-06-05 07:46:30 +08:00
|
|
|
f, err := os.Open(filepath.Join(dataPath, "container.json"))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
2014-06-24 07:54:35 +08:00
|
|
|
var container *libcontainer.Config
|
2014-06-05 07:46:30 +08:00
|
|
|
if err := json.NewDecoder(f).Decode(&container); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return container, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func openLog(name string) error {
|
|
|
|
f, err := os.OpenFile(name, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0755)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
log.SetOutput(f)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2014-06-06 05:28:09 +08:00
|
|
|
|
2014-06-24 07:54:35 +08:00
|
|
|
func loadContainerFromJson(rawData string) (*libcontainer.Config, error) {
|
|
|
|
var container *libcontainer.Config
|
2014-06-06 05:28:09 +08:00
|
|
|
|
|
|
|
if err := json.Unmarshal([]byte(rawData), &container); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return container, nil
|
|
|
|
}
|