github.com/gunjan5/docker@v1.8.2/daemon/execdriver/driver.go (about) 1 package execdriver 2 3 import ( 4 "errors" 5 "io" 6 "os/exec" 7 "time" 8 9 // TODO Windows: Factor out ulimit 10 "github.com/docker/docker/pkg/ulimit" 11 "github.com/opencontainers/runc/libcontainer" 12 "github.com/opencontainers/runc/libcontainer/configs" 13 ) 14 15 // Context is a generic key value pair that allows 16 // arbatrary data to be sent 17 type Context map[string]string 18 19 var ( 20 ErrNotRunning = errors.New("Container is not running") 21 ErrWaitTimeoutReached = errors.New("Wait timeout reached") 22 ErrDriverAlreadyRegistered = errors.New("A driver already registered this docker init function") 23 ErrDriverNotFound = errors.New("The requested docker init has not been found") 24 ) 25 26 type StartCallback func(*ProcessConfig, int) 27 28 // Driver specific information based on 29 // processes registered with the driver 30 type Info interface { 31 IsRunning() bool 32 } 33 34 // Terminal in an interface for drivers to implement 35 // if they want to support Close and Resize calls from 36 // the core 37 type Terminal interface { 38 io.Closer 39 Resize(height, width int) error 40 } 41 42 // ExitStatus provides exit reasons for a container. 43 type ExitStatus struct { 44 // The exit code with which the container exited. 45 ExitCode int 46 47 // Whether the container encountered an OOM. 48 OOMKilled bool 49 } 50 51 type Driver interface { 52 Run(c *Command, pipes *Pipes, startCallback StartCallback) (ExitStatus, error) // Run executes the process and blocks until the process exits and returns the exit code 53 // Exec executes the process in an existing container, blocks until the process exits and returns the exit code 54 Exec(c *Command, processConfig *ProcessConfig, pipes *Pipes, startCallback StartCallback) (int, error) 55 Kill(c *Command, sig int) error 56 Pause(c *Command) error 57 Unpause(c *Command) error 58 Name() string // Driver name 59 Info(id string) Info // "temporary" hack (until we move state from core to plugins) 60 GetPidsForContainer(id string) ([]int, error) // Returns a list of pids for the given container. 61 Terminate(c *Command) error // kill it with fire 62 Clean(id string) error // clean all traces of container exec 63 Stats(id string) (*ResourceStats, error) // Get resource stats for a running container 64 } 65 66 // Network settings of the container 67 type Network struct { 68 Interface *NetworkInterface `json:"interface"` // if interface is nil then networking is disabled 69 Mtu int `json:"mtu"` 70 ContainerID string `json:"container_id"` // id of the container to join network. 71 NamespacePath string `json:"namespace_path"` 72 HostNetworking bool `json:"host_networking"` 73 } 74 75 // IPC settings of the container 76 type Ipc struct { 77 ContainerID string `json:"container_id"` // id of the container to join ipc. 78 HostIpc bool `json:"host_ipc"` 79 } 80 81 // PID settings of the container 82 type Pid struct { 83 HostPid bool `json:"host_pid"` 84 } 85 86 // UTS settings of the container 87 type UTS struct { 88 HostUTS bool `json:"host_uts"` 89 } 90 91 type NetworkInterface struct { 92 Gateway string `json:"gateway"` 93 IPAddress string `json:"ip"` 94 IPPrefixLen int `json:"ip_prefix_len"` 95 MacAddress string `json:"mac"` 96 Bridge string `json:"bridge"` 97 GlobalIPv6Address string `json:"global_ipv6"` 98 LinkLocalIPv6Address string `json:"link_local_ipv6"` 99 GlobalIPv6PrefixLen int `json:"global_ipv6_prefix_len"` 100 IPv6Gateway string `json:"ipv6_gateway"` 101 HairpinMode bool `json:"hairpin_mode"` 102 } 103 104 // TODO Windows: Factor out ulimit.Rlimit 105 type Resources struct { 106 Memory int64 `json:"memory"` 107 MemorySwap int64 `json:"memory_swap"` 108 CpuShares int64 `json:"cpu_shares"` 109 CpusetCpus string `json:"cpuset_cpus"` 110 CpusetMems string `json:"cpuset_mems"` 111 CpuPeriod int64 `json:"cpu_period"` 112 CpuQuota int64 `json:"cpu_quota"` 113 BlkioWeight int64 `json:"blkio_weight"` 114 Rlimits []*ulimit.Rlimit `json:"rlimits"` 115 OomKillDisable bool `json:"oom_kill_disable"` 116 MemorySwappiness int64 `json:"memory_swappiness"` 117 } 118 119 type ResourceStats struct { 120 *libcontainer.Stats 121 Read time.Time `json:"read"` 122 MemoryLimit int64 `json:"memory_limit"` 123 SystemUsage uint64 `json:"system_usage"` 124 } 125 126 type Mount struct { 127 Source string `json:"source"` 128 Destination string `json:"destination"` 129 Writable bool `json:"writable"` 130 Private bool `json:"private"` 131 Slave bool `json:"slave"` 132 } 133 134 // Describes a process that will be run inside a container. 135 type ProcessConfig struct { 136 exec.Cmd `json:"-"` 137 138 Privileged bool `json:"privileged"` 139 User string `json:"user"` 140 Tty bool `json:"tty"` 141 Entrypoint string `json:"entrypoint"` 142 Arguments []string `json:"arguments"` 143 Terminal Terminal `json:"-"` // standard or tty terminal 144 Console string `json:"-"` // dev/console path 145 ConsoleSize [2]int `json:"-"` // h,w of initial console size 146 } 147 148 // TODO Windows: Factor out unused fields such as LxcConfig, AppArmorProfile, 149 // and CgroupParent. 150 // 151 // Process wrapps an os/exec.Cmd to add more metadata 152 type Command struct { 153 ID string `json:"id"` 154 Rootfs string `json:"rootfs"` // root fs of the container 155 ReadonlyRootfs bool `json:"readonly_rootfs"` 156 InitPath string `json:"initpath"` // dockerinit 157 WorkingDir string `json:"working_dir"` 158 ConfigPath string `json:"config_path"` // this should be able to be removed when the lxc template is moved into the driver 159 Network *Network `json:"network"` 160 Ipc *Ipc `json:"ipc"` 161 Pid *Pid `json:"pid"` 162 UTS *UTS `json:"uts"` 163 Resources *Resources `json:"resources"` 164 Mounts []Mount `json:"mounts"` 165 AllowedDevices []*configs.Device `json:"allowed_devices"` 166 AutoCreatedDevices []*configs.Device `json:"autocreated_devices"` 167 CapAdd []string `json:"cap_add"` 168 CapDrop []string `json:"cap_drop"` 169 GroupAdd []string `json:"group_add"` 170 ContainerPid int `json:"container_pid"` // the pid for the process inside a container 171 ProcessConfig ProcessConfig `json:"process_config"` // Describes the init process of the container. 172 ProcessLabel string `json:"process_label"` 173 MountLabel string `json:"mount_label"` 174 LxcConfig []string `json:"lxc_config"` 175 AppArmorProfile string `json:"apparmor_profile"` 176 CgroupParent string `json:"cgroup_parent"` // The parent cgroup for this command. 177 FirstStart bool `json:"first_start"` 178 LayerPaths []string `json:"layer_paths"` // Windows needs to know the layer paths and folder for a command 179 LayerFolder string `json:"layer_folder"` 180 }