Merge pull request #1164 from ijc/configurable-shim-debug
Start of day configuration of shim debug setting
This commit is contained in:
commit
8ab4a61684
@ -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
|
||||
}
|
||||
|
@ -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) {
|
||||
@ -86,6 +88,7 @@ func New(ic *plugin.InitContext) (interface{}, error) {
|
||||
root: ic.Root,
|
||||
remote: !cfg.NoShim,
|
||||
shim: cfg.Shim,
|
||||
shimDebug: cfg.ShimDebug,
|
||||
runtime: cfg.Runtime,
|
||||
monitor: monitor.(runtime.TaskMonitor),
|
||||
tasks: newTaskList(),
|
||||
@ -108,6 +111,7 @@ func New(ic *plugin.InitContext) (interface{}, error) {
|
||||
type Runtime struct {
|
||||
root string
|
||||
shim string
|
||||
shimDebug bool
|
||||
runtime string
|
||||
remote bool
|
||||
address string
|
||||
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user