let user to specify the shim name or path

Signed-off-by: mYmNeo <thomassong@tencent.com>
This commit is contained in:
mYmNeo 2016-04-06 14:42:47 +08:00
parent 5e5daf2b33
commit 4eb27a5926
6 changed files with 21 additions and 9 deletions

View file

@ -89,6 +89,7 @@ type ContainerOpts struct {
Bundle string
Runtime string
RuntimeArgs []string
Shim string
Labels []string
NoPivotRoot bool
Timeout time.Duration
@ -104,6 +105,7 @@ func New(opts ContainerOpts) (Container, error) {
processes: make(map[string]*process),
runtime: opts.Runtime,
runtimeArgs: opts.RuntimeArgs,
shim: opts.Shim,
noPivotRoot: opts.NoPivotRoot,
timeout: opts.Timeout,
}
@ -144,6 +146,7 @@ func Load(root, id string) (Container, error) {
labels: s.Labels,
runtime: s.Runtime,
runtimeArgs: s.RuntimeArgs,
shim: s.Shim,
noPivotRoot: s.NoPivotRoot,
processes: make(map[string]*process),
}
@ -190,6 +193,7 @@ type container struct {
bundle string
runtime string
runtimeArgs []string
shim string
processes map[string]*process
labels []string
oomFds []int

View file

@ -17,8 +17,6 @@ import (
ocs "github.com/opencontainers/specs/specs-go"
)
var shimBinary = os.Args[0] + "-shim"
func getRootIDs(s *specs.Spec) (int, int, error) {
if s == nil {
return 0, 0, nil
@ -145,7 +143,7 @@ func (c *container) Start(checkpoint string, s Stdio) (Process, error) {
if err := os.Mkdir(processRoot, 0755); err != nil {
return nil, err
}
cmd := exec.Command(shimBinary,
cmd := exec.Command(c.shim,
c.id, c.bundle, c.runtime,
)
cmd.Dir = processRoot
@ -185,7 +183,7 @@ func (c *container) Exec(pid string, pspec specs.ProcessSpec, s Stdio) (pp Proce
c.RemoveProcess(pid)
}
}()
cmd := exec.Command(shimBinary,
cmd := exec.Command(c.shim,
c.id, c.bundle, c.runtime,
)
cmd.Dir = processRoot
@ -219,7 +217,7 @@ func (c *container) startCmd(pid string, cmd *exec.Cmd, p *process) error {
if err := cmd.Start(); err != nil {
if exErr, ok := err.(*exec.Error); ok {
if exErr.Err == exec.ErrNotFound || exErr.Err == os.ErrNotExist {
return fmt.Errorf("%s not installed on system", shimBinary)
return fmt.Errorf("%s not installed on system", c.shim)
}
}
return err

View file

@ -61,6 +61,7 @@ type state struct {
Stderr string `json:"stderr"`
Runtime string `json:"runtime"`
RuntimeArgs []string `json:"runtimeArgs"`
Shim string `json:"shim"`
NoPivotRoot bool `json:"noPivotRoot"`
}