diff --git a/linux/bundle.go b/linux/bundle.go index bdac0b1ce..b4b672342 100644 --- a/linux/bundle.go +++ b/linux/bundle.go @@ -56,8 +56,8 @@ type bundle struct { } // NewShim connects to the shim managing the bundle and tasks -func (b *bundle) NewShim(ctx context.Context, binary, grpcAddress string, remote bool) (*client.Client, error) { - opt := client.WithStart(binary, grpcAddress) +func (b *bundle) NewShim(ctx context.Context, binary, grpcAddress string, remote, debug bool) (*client.Client, error) { + opt := client.WithStart(binary, grpcAddress, debug) if !remote { opt = client.WithLocal } diff --git a/linux/runtime.go b/linux/runtime.go index 9bd3d67a8..3785f5c54 100644 --- a/linux/runtime.go +++ b/linux/runtime.go @@ -67,6 +67,8 @@ type Config struct { Runtime string `toml:"runtime,omitempty"` // NoShim calls runc directly from within the pkg NoShim bool `toml:"no_shim,omitempty"` + // Debug enable debug on the shim + ShimDebug bool `toml:"shim_debug,omitempty"` } func New(ic *plugin.InitContext) (interface{}, error) { @@ -83,15 +85,16 @@ func New(ic *plugin.InitContext) (interface{}, error) { } cfg := ic.Config.(*Config) r := &Runtime{ - root: ic.Root, - remote: !cfg.NoShim, - shim: cfg.Shim, - runtime: cfg.Runtime, - monitor: monitor.(runtime.TaskMonitor), - tasks: newTaskList(), - emitter: events.GetPoster(ic.Context), - db: m.(*bolt.DB), - address: ic.Address, + root: ic.Root, + remote: !cfg.NoShim, + shim: cfg.Shim, + shimDebug: cfg.ShimDebug, + runtime: cfg.Runtime, + monitor: monitor.(runtime.TaskMonitor), + tasks: newTaskList(), + emitter: events.GetPoster(ic.Context), + db: m.(*bolt.DB), + address: ic.Address, } tasks, err := r.restoreTasks(ic.Context) if err != nil { @@ -106,11 +109,12 @@ func New(ic *plugin.InitContext) (interface{}, error) { } type Runtime struct { - root string - shim string - runtime string - remote bool - address string + root string + shim string + shimDebug bool + runtime string + remote bool + address string monitor runtime.TaskMonitor tasks *taskList @@ -136,7 +140,7 @@ func (r *Runtime) Create(ctx context.Context, id string, opts runtime.CreateOpts bundle.Delete() } }() - s, err := bundle.NewShim(ctx, r.shim, r.address, r.remote) + s, err := bundle.NewShim(ctx, r.shim, r.address, r.remote, r.shimDebug) if err != nil { return nil, err } diff --git a/linux/shim/client.go b/linux/shim/client.go index 134bbfda2..b2f8e7d65 100644 --- a/linux/shim/client.go +++ b/linux/shim/client.go @@ -27,7 +27,7 @@ import ( type ClientOpt func(context.Context, Config) (shim.ShimClient, io.Closer, error) // WithStart executes a new shim process -func WithStart(binary, address string) ClientOpt { +func WithStart(binary, address string, debug bool) ClientOpt { return func(ctx context.Context, config Config) (shim.ShimClient, io.Closer, error) { socket, err := newSocket(config) if err != nil { @@ -40,13 +40,14 @@ func WithStart(binary, address string) ClientOpt { } defer f.Close() - cmd := newCommand(binary, address, config, f) + cmd := newCommand(binary, address, debug, config, f) if err := reaper.Default.Start(cmd); err != nil { return nil, nil, errors.Wrapf(err, "failed to start shim") } log.G(ctx).WithFields(logrus.Fields{ "pid": cmd.Process.Pid, "address": config.Address, + "debug": debug, }).Infof("shim %s started", binary) if err = sys.SetOOMScore(cmd.Process.Pid, sys.OOMScoreMaxKillable); err != nil { return nil, nil, errors.Wrap(err, "failed to set OOM Score on shim") @@ -55,12 +56,12 @@ func WithStart(binary, address string) ClientOpt { } } -func newCommand(binary, address string, config Config, socket *os.File) *exec.Cmd { +func newCommand(binary, address string, debug bool, config Config, socket *os.File) *exec.Cmd { args := []string{ "--namespace", config.Namespace, "--address", address, } - if config.Debug { + if debug { args = append(args, "--debug") } cmd := exec.Command(binary, args...) @@ -70,7 +71,7 @@ func newCommand(binary, address string, config Config, socket *os.File) *exec.Cm // will be mounted by the shim cmd.SysProcAttr = &atter cmd.ExtraFiles = append(cmd.ExtraFiles, socket) - if config.Debug { + if debug { cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr } @@ -140,7 +141,6 @@ type Config struct { Address string Path string Namespace string - Debug bool } // New returns a new shim client