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