diff --git a/runtime.md b/runtime.md index e5520dfbd..b9c1b6458 100644 --- a/runtime.md +++ b/runtime.md @@ -1,5 +1,51 @@ # Runtime and Lifecycle +## State + +The runtime state for a container is persisted on disk so that external tools can consume and act on this information. +The runtime state is stored in a JSON encoded file. +It is recommended that this file is stored in a temporary filesystem so that it can be removed on a system reboot. +On Linux based systems the state information is stored in `/run/oci`. +The directory structure for a container is `//state.json`. + +* **id** (string) ID is the container's ID. +* **pid** (int) Pid is the main processes id within the container. +* **root** (string) Root is the path to the container's root filesystem specified in the configuration. + +*Example* + +```json +{ + "id": "oci-container", + "pid": 4422, + "root": "/containers/redis" +} +``` + +Linux systems add some platform specific information to the state. + +* **namespaces** Paths to the Linux namespaces setup for the container. +* **cgrousps** Paths to the container's cgroups. +* **externalFds** Paths to the container's main processes STDIO and other external fds. + +*Example Linux* + +```json +{ + "namespaces": { + "process": "/proc/33/ns/pid", + "net": "/proc/33/ns/net" + }, + "cgroups": { + "device": "/sys/fs/cgroup/devices/oci-container", + "cpu": "/sys/fs/cgroup/cpu/oci-container" + }, + "externalFds": [ + "/proc/33/fd/1" + ] +} +``` + ## Lifecycle ### Create diff --git a/spec_linux.go b/spec_linux.go index eb28cbcf3..66750bf28 100644 --- a/spec_linux.go +++ b/spec_linux.go @@ -2,6 +2,9 @@ package specs +// LinuxStateDirectory holds the container's state information. +const LinuxStateDirectory = "/run/oci" + // LinuxSpec is the full specification for linux containers. type LinuxSpec struct { Spec @@ -150,3 +153,16 @@ type Resources struct { // Network restriction configuration. Network Network `json:"network"` } + +type LinuxState struct { + State + // Linux holds platform specific state information for linux. + Linux struct { + // Namespaces holds paths to the container's namespaces on disk. + Namespaces map[string]string `json:"namespaces"` + // Cgroups holds paths to the container's cgroup paths. + Cgroups map[string]string `json:"cgroups"` + // ExternalFds holds paths to the container's STDIO. + ExternalFds []string `json:"externalFds,omitempty"` + } `json:"linux"` +} diff --git a/state.go b/state.go new file mode 100644 index 000000000..a4e814296 --- /dev/null +++ b/state.go @@ -0,0 +1,11 @@ +package specs + +// State holds information about the runtime information of the container. +type State struct { + // ID is the container ID. + ID string `json:"id"` + // Pid is the process id for the container's main process. + Pid int `json:"pid"` + // Root path to the container's root filesystem. + Root string `json:"root"` +}