2014-01-09 02:47:57 +00:00
package execdriver
import (
2014-01-14 00:18:46 +00:00
"errors"
2014-02-21 21:27:15 +00:00
"io"
2014-01-09 23:04:45 +00:00
"os/exec"
2015-01-07 22:43:04 +00:00
"time"
2015-02-11 19:21:38 +00:00
2015-04-27 21:27:00 +00:00
// TODO Windows: Factor out ulimit
2015-02-11 19:21:38 +00:00
"github.com/docker/docker/pkg/ulimit"
2015-07-16 23:00:55 +00:00
"github.com/opencontainers/runc/libcontainer"
"github.com/opencontainers/runc/libcontainer/configs"
2014-01-09 02:47:57 +00:00
)
2014-03-18 20:49:16 +00:00
// Context is a generic key value pair that allows
// arbatrary data to be sent
type Context map [ string ] string
2014-01-14 00:18:46 +00:00
var (
2015-01-08 02:02:08 +00:00
ErrNotRunning = errors . New ( "Container is not running" )
2014-01-14 02:36:59 +00:00
ErrWaitTimeoutReached = errors . New ( "Wait timeout reached" )
ErrDriverAlreadyRegistered = errors . New ( "A driver already registered this docker init function" )
ErrDriverNotFound = errors . New ( "The requested docker init has not been found" )
2014-01-14 00:18:46 +00:00
)
2014-08-26 22:44:00 +00:00
type StartCallback func ( * ProcessConfig , int )
2014-01-13 23:02:12 +00:00
2014-01-15 21:57:07 +00:00
// Driver specific information based on
// processes registered with the driver
2014-01-15 19:46:25 +00:00
type Info interface {
IsRunning ( ) bool
}
2014-02-21 21:27:15 +00:00
// Terminal in an interface for drivers to implement
// if they want to support Close and Resize calls from
// the core
type Terminal interface {
io . Closer
Resize ( height , width int ) error
}
2014-10-08 17:03:57 +00:00
// ExitStatus provides exit reasons for a container.
type ExitStatus struct {
// The exit code with which the container exited.
ExitCode int
// Whether the container encountered an OOM.
OOMKilled bool
}
2014-01-09 23:04:45 +00:00
type Driver interface {
2014-10-30 23:06:54 +00:00
Run ( c * Command , pipes * Pipes , startCallback StartCallback ) ( ExitStatus , error ) // Run executes the process and blocks until the process exits and returns the exit code
2014-10-08 17:03:57 +00:00
// Exec executes the process in an existing container, blocks until the process exits and returns the exit code
2014-09-04 05:29:19 +00:00
Exec ( c * Command , processConfig * ProcessConfig , pipes * Pipes , startCallback StartCallback ) ( int , error )
2014-01-21 00:05:07 +00:00
Kill ( c * Command , sig int ) error
2014-05-21 21:06:18 +00:00
Pause ( c * Command ) error
Unpause ( c * Command ) error
2014-01-28 15:17:51 +00:00
Name ( ) string // Driver name
Info ( id string ) Info // "temporary" hack (until we move state from core to plugins)
GetPidsForContainer ( id string ) ( [ ] int , error ) // Returns a list of pids for the given container.
2014-03-26 06:48:16 +00:00
Terminate ( c * Command ) error // kill it with fire
2014-09-10 07:34:38 +00:00
Clean ( id string ) error // clean all traces of container exec
2015-01-07 22:43:04 +00:00
Stats ( id string ) ( * ResourceStats , error ) // Get resource stats for a running container
2014-01-09 23:04:45 +00:00
}
2014-01-09 02:47:57 +00:00
// Network settings of the container
type Network struct {
2014-05-02 21:17:31 +00:00
Interface * NetworkInterface ` json:"interface" ` // if interface is nil then networking is disabled
Mtu int ` json:"mtu" `
ContainerID string ` json:"container_id" ` // id of the container to join network.
2015-05-06 22:39:29 +00:00
NamespacePath string ` json:"namespace_path" `
2014-05-02 21:17:31 +00:00
HostNetworking bool ` json:"host_networking" `
2014-03-16 19:52:27 +00:00
}
2014-11-10 21:14:17 +00:00
// IPC settings of the container
type Ipc struct {
ContainerID string ` json:"container_id" ` // id of the container to join ipc.
HostIpc bool ` json:"host_ipc" `
}
2014-11-25 20:10:53 +00:00
// PID settings of the container
type Pid struct {
HostPid bool ` json:"host_pid" `
}
2015-05-05 22:32:36 +00:00
// UTS settings of the container
type UTS struct {
HostUTS bool ` json:"host_uts" `
}
2014-03-16 19:52:27 +00:00
type NetworkInterface struct {
2015-01-08 23:03:19 +00:00
Gateway string ` json:"gateway" `
IPAddress string ` json:"ip" `
IPPrefixLen int ` json:"ip_prefix_len" `
MacAddress string ` json:"mac" `
Bridge string ` json:"bridge" `
GlobalIPv6Address string ` json:"global_ipv6" `
LinkLocalIPv6Address string ` json:"link_local_ipv6" `
GlobalIPv6PrefixLen int ` json:"global_ipv6_prefix_len" `
IPv6Gateway string ` json:"ipv6_gateway" `
2014-11-11 00:19:16 +00:00
HairpinMode bool ` json:"hairpin_mode" `
2014-01-09 02:47:57 +00:00
}
2015-04-27 21:27:00 +00:00
// TODO Windows: Factor out ulimit.Rlimit
2014-01-20 21:23:02 +00:00
type Resources struct {
2015-07-12 07:46:33 +00:00
Memory int64 ` json:"memory" `
MemorySwap int64 ` json:"memory_swap" `
CpuShares int64 ` json:"cpu_shares" `
CpusetCpus string ` json:"cpuset_cpus" `
CpusetMems string ` json:"cpuset_mems" `
CpuPeriod int64 ` json:"cpu_period" `
CpuQuota int64 ` json:"cpu_quota" `
BlkioWeight int64 ` json:"blkio_weight" `
Rlimits [ ] * ulimit . Rlimit ` json:"rlimits" `
OomKillDisable bool ` json:"oom_kill_disable" `
MemorySwappiness int64 ` json:"memory_swappiness" `
2014-01-20 21:23:02 +00:00
}
2015-01-07 22:43:04 +00:00
type ResourceStats struct {
2015-03-05 17:55:14 +00:00
* libcontainer . Stats
2015-01-08 00:22:42 +00:00
Read time . Time ` json:"read" `
MemoryLimit int64 ` json:"memory_limit" `
SystemUsage uint64 ` json:"system_usage" `
2015-01-07 22:43:04 +00:00
}
2014-03-03 15:15:29 +00:00
type Mount struct {
Source string ` json:"source" `
Destination string ` json:"destination" `
Writable bool ` json:"writable" `
Private bool ` json:"private" `
2014-09-13 16:42:10 +00:00
Slave bool ` json:"slave" `
2014-03-03 15:15:29 +00:00
}
2014-08-26 22:05:37 +00:00
// Describes a process that will be run inside a container.
type ProcessConfig struct {
2014-01-21 00:05:07 +00:00
exec . Cmd ` json:"-" `
2014-01-10 19:44:35 +00:00
2015-05-27 20:15:14 +00:00
Privileged bool ` json:"privileged" `
User string ` json:"user" `
Tty bool ` json:"tty" `
Entrypoint string ` json:"entrypoint" `
Arguments [ ] string ` json:"arguments" `
Terminal Terminal ` json:"-" ` // standard or tty terminal
Console string ` json:"-" ` // dev/console path
ConsoleSize [ 2 ] int ` json:"-" ` // h,w of initial console size
2014-08-26 22:05:37 +00:00
}
2015-04-27 21:27:00 +00:00
// TODO Windows: Factor out unused fields such as LxcConfig, AppArmorProfile,
// and CgroupParent.
//
2014-08-26 22:05:37 +00:00
// Process wrapps an os/exec.Cmd to add more metadata
type Command struct {
2014-09-29 22:40:26 +00:00
ID string ` json:"id" `
2015-01-13 21:52:51 +00:00
Rootfs string ` json:"rootfs" ` // root fs of the container
ReadonlyRootfs bool ` json:"readonly_rootfs" `
2014-09-29 22:40:26 +00:00
InitPath string ` json:"initpath" ` // dockerinit
WorkingDir string ` json:"working_dir" `
ConfigPath string ` json:"config_path" ` // this should be able to be removed when the lxc template is moved into the driver
Network * Network ` json:"network" `
2014-11-10 21:14:17 +00:00
Ipc * Ipc ` json:"ipc" `
2014-11-25 20:10:53 +00:00
Pid * Pid ` json:"pid" `
2015-05-05 22:32:36 +00:00
UTS * UTS ` json:"uts" `
2014-09-29 22:40:26 +00:00
Resources * Resources ` json:"resources" `
Mounts [ ] Mount ` json:"mounts" `
2015-03-05 17:55:14 +00:00
AllowedDevices [ ] * configs . Device ` json:"allowed_devices" `
AutoCreatedDevices [ ] * configs . Device ` json:"autocreated_devices" `
2014-09-29 22:40:26 +00:00
CapAdd [ ] string ` json:"cap_add" `
CapDrop [ ] string ` json:"cap_drop" `
2015-06-17 18:39:17 +00:00
GroupAdd [ ] string ` json:"group_add" `
2014-09-29 22:40:26 +00:00
ContainerPid int ` json:"container_pid" ` // the pid for the process inside a container
ProcessConfig ProcessConfig ` json:"process_config" ` // Describes the init process of the container.
ProcessLabel string ` json:"process_label" `
MountLabel string ` json:"mount_label" `
LxcConfig [ ] string ` json:"lxc_config" `
2014-09-29 23:34:45 +00:00
AppArmorProfile string ` json:"apparmor_profile" `
2015-03-16 22:42:15 +00:00
CgroupParent string ` json:"cgroup_parent" ` // The parent cgroup for this command.
2015-05-27 20:15:14 +00:00
FirstStart bool ` json:"first_start" `
LayerPaths [ ] string ` json:"layer_paths" ` // Windows needs to know the layer paths and folder for a command
LayerFolder string ` json:"layer_folder" `
2014-01-09 23:04:45 +00:00
}