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

@ -48,13 +48,18 @@ var daemonFlags = []cli.Flag{
cli.StringFlag{ cli.StringFlag{
Name: "runtime,r", Name: "runtime,r",
Value: "runc", Value: "runc",
Usage: "name of the OCI compliant runtime to use when executing containers", Usage: "name or path of the OCI compliant runtime to use when executing containers",
}, },
cli.StringSliceFlag{ cli.StringSliceFlag{
Name: "runtime-args", Name: "runtime-args",
Value: &cli.StringSlice{}, Value: &cli.StringSlice{},
Usage: "specify additional runtime args", Usage: "specify additional runtime args",
}, },
cli.StringFlag{
Name: "shim",
Value: "containerd-shim",
Usage: "Name or path of shim",
},
cli.StringFlag{ cli.StringFlag{
Name: "pprof-address", Name: "pprof-address",
Usage: "http address to listen for pprof events", Usage: "http address to listen for pprof events",
@ -86,6 +91,7 @@ func main() {
10, 10,
context.String("runtime"), context.String("runtime"),
context.StringSlice("runtime-args"), context.StringSlice("runtime-args"),
context.String("shim"),
context.Duration("start-timeout"), context.Duration("start-timeout"),
); err != nil { ); err != nil {
logrus.Fatal(err) logrus.Fatal(err)
@ -96,7 +102,7 @@ func main() {
} }
} }
func daemon(address, stateDir string, concurrency int, runtimeName string, runtimeArgs []string, timeout time.Duration) error { func daemon(address, stateDir string, concurrency int, runtimeName string, runtimeArgs []string, shimName string, timeout time.Duration) error {
// setup a standard reaper so that we don't leave any zombies if we are still alive // setup a standard reaper so that we don't leave any zombies if we are still alive
// this is just good practice because we are spawning new processes // this is just good practice because we are spawning new processes
s := make(chan os.Signal, 2048) s := make(chan os.Signal, 2048)
@ -104,7 +110,7 @@ func daemon(address, stateDir string, concurrency int, runtimeName string, runti
if err := osutils.SetSubreaper(1); err != nil { if err := osutils.SetSubreaper(1); err != nil {
logrus.WithField("error", err).Error("containerd: set subpreaper") logrus.WithField("error", err).Error("containerd: set subpreaper")
} }
sv, err := supervisor.New(stateDir, runtimeName, runtimeArgs, timeout) sv, err := supervisor.New(stateDir, runtimeName, shimName, runtimeArgs, timeout)
if err != nil { if err != nil {
return err return err
} }

View file

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

View file

@ -17,8 +17,6 @@ import (
ocs "github.com/opencontainers/specs/specs-go" ocs "github.com/opencontainers/specs/specs-go"
) )
var shimBinary = os.Args[0] + "-shim"
func getRootIDs(s *specs.Spec) (int, int, error) { func getRootIDs(s *specs.Spec) (int, int, error) {
if s == nil { if s == nil {
return 0, 0, 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 { if err := os.Mkdir(processRoot, 0755); err != nil {
return nil, err return nil, err
} }
cmd := exec.Command(shimBinary, cmd := exec.Command(c.shim,
c.id, c.bundle, c.runtime, c.id, c.bundle, c.runtime,
) )
cmd.Dir = processRoot cmd.Dir = processRoot
@ -185,7 +183,7 @@ func (c *container) Exec(pid string, pspec specs.ProcessSpec, s Stdio) (pp Proce
c.RemoveProcess(pid) c.RemoveProcess(pid)
} }
}() }()
cmd := exec.Command(shimBinary, cmd := exec.Command(c.shim,
c.id, c.bundle, c.runtime, c.id, c.bundle, c.runtime,
) )
cmd.Dir = processRoot 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 err := cmd.Start(); err != nil {
if exErr, ok := err.(*exec.Error); ok { if exErr, ok := err.(*exec.Error); ok {
if exErr.Err == exec.ErrNotFound || exErr.Err == os.ErrNotExist { 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 return err

View file

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

View file

@ -27,6 +27,7 @@ func (s *Supervisor) start(t *StartTask) error {
Bundle: t.BundlePath, Bundle: t.BundlePath,
Runtime: s.runtime, Runtime: s.runtime,
RuntimeArgs: s.runtimeArgs, RuntimeArgs: s.runtimeArgs,
Shim: s.shim,
Labels: t.Labels, Labels: t.Labels,
NoPivotRoot: t.NoPivotRoot, NoPivotRoot: t.NoPivotRoot,
Timeout: s.timeout, Timeout: s.timeout,

View file

@ -18,7 +18,7 @@ const (
) )
// New returns an initialized Process supervisor. // New returns an initialized Process supervisor.
func New(stateDir string, runtimeName string, runtimeArgs []string, timeout time.Duration) (*Supervisor, error) { func New(stateDir string, runtimeName, shimName string, runtimeArgs []string, timeout time.Duration) (*Supervisor, error) {
startTasks := make(chan *startTask, 10) startTasks := make(chan *startTask, 10)
if err := os.MkdirAll(stateDir, 0755); err != nil { if err := os.MkdirAll(stateDir, 0755); err != nil {
return nil, err return nil, err
@ -41,6 +41,7 @@ func New(stateDir string, runtimeName string, runtimeArgs []string, timeout time
monitor: monitor, monitor: monitor,
runtime: runtimeName, runtime: runtimeName,
runtimeArgs: runtimeArgs, runtimeArgs: runtimeArgs,
shim: shimName,
timeout: timeout, timeout: timeout,
} }
if err := setupEventLog(s); err != nil { if err := setupEventLog(s); err != nil {
@ -109,6 +110,7 @@ type Supervisor struct {
// name of the OCI compatible runtime used to execute containers // name of the OCI compatible runtime used to execute containers
runtime string runtime string
runtimeArgs []string runtimeArgs []string
shim string
containers map[string]*containerInfo containers map[string]*containerInfo
startTasks chan *startTask startTasks chan *startTask
// we need a lock around the subscribers map only because additions and deletions from // we need a lock around the subscribers map only because additions and deletions from