Update go-runc to afca56d262e694d9056e937a0877a39ab879aeb4

This includes fixes for --console-socket in runc as well as additional
APIs for runc commands.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2017-01-20 13:42:14 -08:00
parent 7101c7a9e2
commit b895c98358
3 changed files with 67 additions and 29 deletions

View File

@ -1,5 +1,5 @@
# go-runc client for runc; master as of 12/16/2016
github.com/crosbymichael/go-runc 2fdd3cd06f7443a55f6eb14ead2cac507506e718
# go-runc client for runc; master as of 01/20/2017
github.com/crosbymichael/go-runc afca56d262e694d9056e937a0877a39ab879aeb4
# go-metrics client to prometheus; master as of 12/16/2016
github.com/docker/go-metrics 0f35294225552d968a13f9c5bc71a3fa44b2eb87
# prometheus client; latest release as of 12/16/2016

View File

@ -1,9 +1,14 @@
package runc
type Event struct {
// Type are the event type generated by runc
// If the type is "error" then check the Err field on the event for
// the actual error
Type string `json:"type"`
ID string `json:"id"`
Stats *Stats `json:"data,omitempty"`
// Err has a read error if we were unable to decode the event from runc
Err error `json:"-"`
}
type Stats struct {

View File

@ -13,7 +13,6 @@ import (
"time"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
)
// Format is the type of log formatting options avaliable
@ -23,14 +22,19 @@ const (
none Format = ""
JSON Format = "json"
Text Format = "text"
// DefaultCommand is the default command for Runc
DefaultCommand string = "runc"
)
// Runc is the client to the runc cli
type Runc struct {
Root string
Debug bool
Log string
LogFormat Format
//If command is empty, DefaultCommand is used
Command string
Root string
Debug bool
Log string
LogFormat Format
PdeathSignal syscall.Signal
}
// List returns all containers created inside the provided runc root directory
@ -62,11 +66,11 @@ func (r *Runc) State(context context.Context, id string) (*Container, error) {
type CreateOpts struct {
IO
// PidFile is a path to where a pid file should be created
PidFile string
Console string
Detach bool
NoPivot bool
NoNewKeyring bool
PidFile string
ConsoleSocket string
Detach bool
NoPivot bool
NoNewKeyring bool
}
type IO struct {
@ -103,8 +107,8 @@ func (o *CreateOpts) args() (out []string) {
if o.PidFile != "" {
out = append(out, "--pid-file", o.PidFile)
}
if o.Console != "" {
out = append(out, "--console", o.Console)
if o.ConsoleSocket != "" {
out = append(out, "--console-socket", o.ConsoleSocket)
}
if o.NoPivot {
out = append(out, "--no-pivot")
@ -138,13 +142,13 @@ func (r *Runc) Start(context context.Context, id string) error {
type ExecOpts struct {
IO
PidFile string
Uid int
Gid int
Cwd string
Tty bool
Console string
Detach bool
PidFile string
Uid int
Gid int
Cwd string
Tty bool
ConsoleSocket string
Detach bool
}
func (o *ExecOpts) args() (out []string) {
@ -152,8 +156,8 @@ func (o *ExecOpts) args() (out []string) {
if o.Tty {
out = append(out, "--tty")
}
if o.Console != "" {
out = append(out, "--console", o.Console)
if o.ConsoleSocket != "" {
out = append(out, "--console-socket", o.ConsoleSocket)
}
if o.Cwd != "" {
out = append(out, "--cwd", o.Cwd)
@ -217,9 +221,27 @@ func (r *Runc) Delete(context context.Context, id string) error {
return runOrError(r.command(context, "delete", id))
}
// KillOpts specifies options for killing a container and its processes
type KillOpts struct {
All bool
}
func (o *KillOpts) args() (out []string) {
if o.All {
out = append(out, "--all")
}
return out
}
// Kill sends the specified signal to the container
func (r *Runc) Kill(context context.Context, id string, sig int) error {
return runOrError(r.command(context, "kill", id, strconv.Itoa(sig)))
func (r *Runc) Kill(context context.Context, id string, sig int, opts *KillOpts) error {
args := []string{
"kill",
}
if opts != nil {
args = append(args, opts.args()...)
}
return runOrError(r.command(context, append(args, id, strconv.Itoa(sig))...))
}
// Stats return the stats for a container like cpu, memory, and io
@ -270,8 +292,10 @@ func (r *Runc) Events(context context.Context, id string, interval time.Duration
if err == io.EOF {
return
}
logrus.WithError(err).Error("runc: decode event")
continue
e = Event{
Type: "error",
Err: err,
}
}
c <- &e
}
@ -319,6 +343,15 @@ func (r *Runc) args() (out []string) {
}
func (r *Runc) command(context context.Context, args ...string) *exec.Cmd {
return exec.CommandContext(context,
"runc", append(r.args(), args...)...)
command := r.Command
if command == "" {
command = DefaultCommand
}
cmd := exec.CommandContext(context, command, append(r.args(), args...)...)
if r.PdeathSignal != 0 {
cmd.SysProcAttr = &syscall.SysProcAttr{
Pdeathsig: r.PdeathSignal,
}
}
return cmd
}