Documentation
¶
Overview ¶
Package runc provides Go bindings for invoking and interacting with the runc command-line interface.
Index ¶
- Variables
- func LeaveRunning(args []string) []string
- func PreDump(args []string) []string
- func ReadPidFile(path string) (int, error)
- func WithExtraEnv(ctx context.Context, env ...string) context.Context
- type Blkio
- type BlkioEntry
- type CgroupMode
- type CheckpointAction
- type CheckpointOpts
- type ConsoleSocket
- type Container
- type Cpu
- type CpuUsage
- type CreateOpts
- type DeleteOpts
- type Event
- type ExecOpts
- type Exit
- type ExitError
- type Format
- type Hugetlb
- type IO
- type IOOpt
- type IOOption
- type KillOpts
- type Memory
- type MemoryEntry
- type NetworkInterface
- type PidfdSocket
- type Pids
- type ProcessMonitor
- type RestoreOpts
- type Runc
- func (r *Runc) Checkpoint(context context.Context, id string, opts *CheckpointOpts, ...) error
- func (r *Runc) Create(context context.Context, id, bundle string, opts *CreateOpts) error
- func (r *Runc) Delete(context context.Context, id string, opts *DeleteOpts) error
- func (r *Runc) Events(context context.Context, id string, interval time.Duration) (chan *Event, error)
- func (r *Runc) Exec(context context.Context, id string, spec specs.Process, opts *ExecOpts) error
- func (r *Runc) Features(context context.Context) (*features.Features, error)
- func (r *Runc) Kill(context context.Context, id string, sig int, opts *KillOpts) error
- func (r *Runc) List(context context.Context) ([]*Container, error)
- func (r *Runc) Pause(context context.Context, id string) error
- func (r *Runc) Ps(context context.Context, id string) ([]int, error)
- func (r *Runc) Restore(context context.Context, id, bundle string, opts *RestoreOpts) (int, error)
- func (r *Runc) Resume(context context.Context, id string) error
- func (r *Runc) Run(context context.Context, id, bundle string, opts *CreateOpts) (int, error)
- func (r *Runc) Start(context context.Context, id string) error
- func (r *Runc) State(context context.Context, id string) (*Container, error)
- func (r *Runc) Stats(context context.Context, id string) (*Stats, error)
- func (r *Runc) Top(context context.Context, id string, psOptions string) (*TopResults, error)
- func (r *Runc) Update(context context.Context, id string, resources *specs.LinuxResources) error
- func (r *Runc) Version(context context.Context) (Version, error)
- type Socket
- type StartCloser
- type Stats
- type Throttling
- type TopResults
- type Version
Constants ¶
This section is empty.
Variables ¶
var DefaultCommand = "runc"
DefaultCommand is the default command for Runc
var ErrParseRuncVersion = errors.New("unable to parse runc version")
ErrParseRuncVersion is kept for backward compatibility with older versions.
Deprecated: ErrParseRuncVersion is never emitted, and should not be used.
Functions ¶
func LeaveRunning ¶
LeaveRunning keeps the container running after the checkpoint has been completed
func ReadPidFile ¶
ReadPidFile reads the pid file at the provided path and returns the pid or an error if the read and conversion is unsuccessful
func WithExtraEnv ¶ added in v1.2.0
WithExtraEnv returns a context which adds the given "KEY=VALUE" entries to the environment of every runc invocation made with it. Entries are appended after the inherited environment, so they replace inherited variables of the same name, and repeated calls accumulate.
Types ¶
type Blkio ¶
type Blkio struct {
IoServiceBytesRecursive []BlkioEntry `json:"ioServiceBytesRecursive,omitempty"`
IoServicedRecursive []BlkioEntry `json:"ioServicedRecursive,omitempty"`
IoQueuedRecursive []BlkioEntry `json:"ioQueueRecursive,omitempty"`
IoServiceTimeRecursive []BlkioEntry `json:"ioServiceTimeRecursive,omitempty"`
IoWaitTimeRecursive []BlkioEntry `json:"ioWaitTimeRecursive,omitempty"`
IoMergedRecursive []BlkioEntry `json:"ioMergedRecursive,omitempty"`
IoTimeRecursive []BlkioEntry `json:"ioTimeRecursive,omitempty"`
SectorsRecursive []BlkioEntry `json:"sectorsRecursive,omitempty"`
}
Blkio represents the statistical information from block IO devices
type BlkioEntry ¶
type BlkioEntry struct {
Major uint64 `json:"major,omitempty"`
Minor uint64 `json:"minor,omitempty"`
Op string `json:"op,omitempty"`
Value uint64 `json:"value,omitempty"`
}
BlkioEntry represents a block IO entry in the IO stats
type CgroupMode ¶
type CgroupMode string
CgroupMode defines the cgroup mode used for checkpointing
const ( // Soft is the "soft" cgroup mode Soft CgroupMode = "soft" // Full is the "full" cgroup mode Full CgroupMode = "full" // Strict is the "strict" cgroup mode Strict CgroupMode = "strict" )
type CheckpointAction ¶
CheckpointAction represents specific actions executed during checkpoint/restore
type CheckpointOpts ¶
type CheckpointOpts struct {
// ImagePath is the path for saving the criu image file
ImagePath string
// WorkDir is the working directory for criu
WorkDir string
// ParentPath is the path for previous image files from a pre-dump
ParentPath string
// AllowOpenTCP allows open tcp connections to be checkpointed
AllowOpenTCP bool
// AllowExternalUnixSockets allows external unix sockets to be checkpointed
AllowExternalUnixSockets bool
// AllowTerminal allows the terminal(pty) to be checkpointed with a container
AllowTerminal bool
// CriuPageServer is the address:port for the criu page server
CriuPageServer string
// FileLocks handle file locks held by the container
FileLocks bool
// Cgroups is the cgroup mode for how to handle the checkpoint of a container's cgroups
Cgroups CgroupMode
// EmptyNamespaces creates a namespace for the container but does not save its properties
// Provide the namespaces you wish to be checkpointed without their settings on restore
EmptyNamespaces []string
// LazyPages uses userfaultfd to lazily restore memory pages
LazyPages bool
// StatusFile is the file criu writes \0 to once lazy-pages is ready
StatusFile *os.File
ExtraArgs []string
}
CheckpointOpts holds the options for performing a criu checkpoint using runc
type ConsoleSocket ¶
type ConsoleSocket interface {
Path() string
}
ConsoleSocket handles the path of the socket for console access
type Container ¶
type Container struct {
ID string `json:"id"`
Pid int `json:"pid"`
Status string `json:"status"`
Bundle string `json:"bundle"`
Rootfs string `json:"rootfs"`
Created time.Time `json:"created"`
Annotations map[string]string `json:"annotations"`
}
Container hold information for a runc container
type Cpu ¶
type Cpu struct {
Usage CpuUsage `json:"usage,omitempty"`
Throttling Throttling `json:"throttling,omitempty"`
}
Cpu represents the CPU usage and throttling statistics
type CpuUsage ¶
type CpuUsage struct {
// Units: nanoseconds.
Total uint64 `json:"total,omitempty"`
Percpu []uint64 `json:"percpu,omitempty"`
Kernel uint64 `json:"kernel"`
User uint64 `json:"user"`
}
CpuUsage represents the CPU usage statistics
type CreateOpts ¶
type CreateOpts struct {
IO
// PidFile is a path to where a pid file should be created
PidFile string
ConsoleSocket ConsoleSocket
// PidfdSocket receives a pidfd referencing the container's init process,
// which lets the caller signal or wait on it without racing against pid
// reuse. Requires runc v1.2.0 or newer.
PidfdSocket PidfdSocket
Detach bool
NoPivot bool
NoNewKeyring bool
ExtraFiles []*os.File
Started chan<- int
ExtraArgs []string
}
CreateOpts holds all the options information for calling runc with supported options
type DeleteOpts ¶
DeleteOpts holds the deletion options for calling `runc delete`
type Event ¶
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:"-"`
}
Event is a struct to pass runc event information
type ExecOpts ¶
type ExecOpts struct {
IO
LogFile string
PidFile string
ConsoleSocket ConsoleSocket
// PidfdSocket receives a pidfd referencing the exec'd process, which lets
// the caller signal or wait on it without racing against pid reuse.
// Requires runc v1.2.0 or newer.
PidfdSocket PidfdSocket
Detach bool
Started chan<- int
ExtraArgs []string
}
ExecOpts holds optional settings when starting an exec process with runc
type ExitError ¶
type ExitError struct {
Status int
}
ExitError holds the status return code when a process exits with an error code
type Hugetlb ¶
type Hugetlb struct {
Usage uint64 `json:"usage,omitempty"`
Max uint64 `json:"max,omitempty"`
Failcnt uint64 `json:"failcnt"`
}
Hugetlb represents the detailed hugetlb component of the statistics data
type IO ¶
type IO interface {
io.Closer
Stdin() io.WriteCloser
Stdout() io.ReadCloser
Stderr() io.ReadCloser
Set(*exec.Cmd)
}
IO is the terminal IO interface
type Memory ¶
type Memory struct {
Cache uint64 `json:"cache,omitempty"`
Usage MemoryEntry `json:"usage,omitempty"`
Swap MemoryEntry `json:"swap,omitempty"`
Kernel MemoryEntry `json:"kernel,omitempty"`
KernelTCP MemoryEntry `json:"kernelTCP,omitempty"`
Raw map[string]uint64 `json:"raw,omitempty"`
}
Memory represents the collection of memory statistics from the process
type MemoryEntry ¶
type MemoryEntry struct {
Limit uint64 `json:"limit"`
Usage uint64 `json:"usage,omitempty"`
Max uint64 `json:"max,omitempty"`
Failcnt uint64 `json:"failcnt"`
}
MemoryEntry represents an item in the memory use/statistics
type NetworkInterface ¶ added in v1.2.0
type PidfdSocket ¶ added in v1.2.0
type PidfdSocket interface {
Path() string
}
PidfdSocket handles the path of the socket which receives the pidfd of the process runc creates.
type Pids ¶
type Pids struct {
Current uint64 `json:"current,omitempty"`
Limit uint64 `json:"limit,omitempty"`
}
Pids represents the process ID information
type ProcessMonitor ¶
type ProcessMonitor interface {
Start(*exec.Cmd) (chan Exit, error)
StartLocked(*exec.Cmd) (chan Exit, error)
Wait(*exec.Cmd, chan Exit) (int, error)
}
ProcessMonitor is an interface for process monitoring.
It allows daemons using go-runc to have a SIGCHLD handler to handle exits without introducing races between the handler and go's exec.Cmd.
ProcessMonitor also provides a StartLocked method which is similar to Start, but locks the goroutine used to start the process to an OS thread (for example: when Pdeathsig is set).
var Monitor ProcessMonitor = &defaultMonitor{}
Monitor is the default ProcessMonitor for handling runc process exit
type RestoreOpts ¶
type RestoreOpts struct {
CheckpointOpts
IO
Detach bool
PidFile string
NoSubreaper bool
NoPivot bool
ConsoleSocket ConsoleSocket
ExtraArgs []string
}
RestoreOpts holds the options for performing a criu restore using runc
type Runc ¶
type Runc struct {
// Command overrides the name of the runc binary. If empty, DefaultCommand
// is used.
Command string
// WorkDir sets the working directory of the runc process. If empty, the
// working directory of the calling process is used.
WorkDir string
Root string
Debug bool
Log string
LogFormat Format
// PdeathSignal sets a signal the child process will receive when the
// parent dies.
//
// When Pdeathsig is set, command invocations will call runtime.LockOSThread
// to prevent OS thread termination from spuriously triggering the
// signal. See https://github.com/golang/go/issues/27505 and
// https://github.com/golang/go/blob/126c22a09824a7b52c019ed9a1d198b4e7781676/src/syscall/exec_linux.go#L48-L51
//
// A program with GOMAXPROCS=1 might hang because of the use of
// runtime.LockOSThread. Callers should ensure they retain at least one
// unlocked thread.
PdeathSignal syscall.Signal // using syscall.Signal to allow compilation on non-unix (unix.Syscall is an alias for syscall.Signal)
Setpgid bool
// Criu sets the path to the criu binary used for checkpoint and restore.
//
// Deprecated: runc option --criu is now ignored (with a warning), and the
// option will be removed entirely in a future release. Users who need a non-
// standard criu binary should rely on the standard way of looking up binaries
// in $PATH.
Criu string
SystemdCgroup bool
Rootless *bool // nil stands for "auto"
ExtraArgs []string
}
Runc is the client to the runc cli
Fields here apply to every invocation. For per-invocation settings see the Opts types and WithExtraEnv.
func (*Runc) Checkpoint ¶
func (r *Runc) Checkpoint(context context.Context, id string, opts *CheckpointOpts, actions ...CheckpointAction) error
Checkpoint allows you to checkpoint a container using criu
func (*Runc) Create ¶
Create creates a new container and returns its pid if it was created successfully
func (*Runc) Events ¶
func (r *Runc) Events(context context.Context, id string, interval time.Duration) (chan *Event, error)
Events returns an event stream from runc for a container with stats and OOM notifications
func (*Runc) Exec ¶
Exec executes an additional process inside the container based on a full OCI Process specification
func (*Runc) Features ¶ added in v1.1.0
Features shows the features implemented by the runtime.
Availability:
- runc: supported since runc v1.1.0
- crun: supported since crun v1.8.6
- youki: https://github.com/containers/youki/issues/815
func (*Runc) Run ¶
Run runs the create, start, delete lifecycle of the container and returns its exit status after it has exited
type Socket ¶
type Socket struct {
// contains filtered or unexported fields
}
Socket is a unix socket that accepts a file descriptor sent by runc, such as the pty master for the container's console or the pidfd of the process runc creates.
func NewConsoleSocket ¶
NewConsoleSocket creates a new unix socket at the provided path to accept a pty master created by runc for use by the container
func NewPidfdSocket ¶ added in v1.2.0
NewPidfdSocket creates a new unix socket at the provided path to accept the pidfd of the process runc creates.
Requires runc v1.2.0 or newer and a v5.3 or newer kernel.
func NewTempConsoleSocket ¶
NewTempConsoleSocket returns a temp console socket for use with a container On Close(), the socket is deleted
func NewTempPidfdSocket ¶ added in v1.2.0
NewTempPidfdSocket returns a temp socket to accept the pidfd of the process runc creates. On Close(), the socket is deleted.
Requires runc v1.2.0 or newer and a v5.3 or newer kernel.
func (*Socket) ReceiveMaster ¶
ReceiveMaster blocks until the socket receives the pty master
func (*Socket) ReceivePidfd ¶ added in v1.2.0
ReceivePidfd blocks until the socket receives the pidfd of the process runc created. The pidfd refers to the container's init process for create and run, and to the exec'd process for exec.
The pidfd is sent while the process is being set up, which is before `runc create` returns and before the container's start fifo is opened, so it is safe to receive it before starting the container.
It is the caller's responsibility to close the returned file. The pidfd can be used to signal or wait on the process without the pid reuse races that come with a raw pid, e.g. with unix.PidfdSendSignal.
type StartCloser ¶
type StartCloser interface {
CloseAfterStart() error
}
StartCloser is an interface to handle IO closure after start
type Stats ¶
type Stats struct {
Cpu Cpu `json:"cpu"` //revive:disable
Memory Memory `json:"memory"`
Pids Pids `json:"pids"`
Blkio Blkio `json:"blkio"`
Hugetlb map[string]Hugetlb `json:"hugetlb"`
NetworkInterfaces []*NetworkInterface `json:"network_interfaces"`
}
Stats is statistical information from the runc process
type Throttling ¶
type Throttling struct {
Periods uint64 `json:"periods,omitempty"`
ThrottledPeriods uint64 `json:"throttledPeriods,omitempty"`
ThrottledTime uint64 `json:"throttledTime,omitempty"`
}
Throttling represents the throttling statistics
type TopResults ¶
type TopResults struct {
// Processes running in the container, where each is process is an array of values corresponding to the headers
Processes [][]string `json:"Processes"`
// Headers are the names of the columns
Headers []string `json:"Headers"`
}
TopResults represents the structured data of the full ps output
func ParsePSOutput ¶
func ParsePSOutput(output []byte) (*TopResults, error)
ParsePSOutput parses the runtime's ps raw output and returns a TopResults