execution: add shim runtime

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
Kenfe-Mickael Laventure
2017-01-12 10:32:09 -08:00
parent 37a113f9fb
commit 5b40adf9af
9 changed files with 852 additions and 21 deletions

View File

@@ -4,32 +4,46 @@ import (
"io/ioutil"
"os"
"path/filepath"
"github.com/pkg/errors"
)
const processesDirName = "processes"
type StateDir string
func LoadStateDir(root, id string) (StateDir, error) {
path := filepath.Join(root, id)
if _, err := os.Stat(path); err != nil {
return "", errors.Wrap(err, "could not find container statedir")
}
return StateDir(path), nil
}
func NewStateDir(root, id string) (StateDir, error) {
path := filepath.Join(root, id)
if err := os.Mkdir(path, 0700); err != nil {
return "", err
return "", errors.Wrap(err, "could not create container statedir")
}
if err := os.Mkdir(StateDir(path).processesDir(), 0700); err != nil {
os.RemoveAll(path)
return "", err
return "", errors.Wrap(err, "could not create processes statedir")
}
return StateDir(path), nil
}
func (s StateDir) Delete() error {
return os.RemoveAll(string(s))
err := os.RemoveAll(string(s))
if err != nil {
return errors.Wrapf(err, "failed to remove statedir %s", string(s))
}
return nil
}
func (s StateDir) NewProcess(id string) (dir string, err error) {
dir = filepath.Join(s.processesDir(), id)
if err = os.Mkdir(dir, 0700); err != nil {
return "", err
return "", errors.Wrap(err, "could not create process statedir")
}
return dir, nil
@@ -40,14 +54,18 @@ func (s StateDir) ProcessDir(id string) string {
}
func (s StateDir) DeleteProcess(id string) error {
return os.RemoveAll(filepath.Join(s.processesDir(), id))
err := os.RemoveAll(filepath.Join(s.processesDir(), id))
if err != nil {
return errors.Wrapf(err, "failed to remove process %d statedir", id)
}
return nil
}
func (s StateDir) Processes() ([]string, error) {
procsDir := s.processesDir()
dirs, err := ioutil.ReadDir(procsDir)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "could not list processes statedir")
}
paths := make([]string, 0)