Skip to content

Commit

Permalink
Add runtime state configuration and structs
Browse files Browse the repository at this point in the history
This adds runtime state information for oci container's so that it can
be persisted and used by external tools.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
  • Loading branch information
crosbymichael committed Jul 29, 2015
1 parent d619f2f commit da393af
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
46 changes: 46 additions & 0 deletions 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 `<root>/<containerID>/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
Expand Down
16 changes: 16 additions & 0 deletions spec_linux.go
Expand Up @@ -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
Expand Down Expand Up @@ -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"`
}
11 changes: 11 additions & 0 deletions 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"`
}

0 comments on commit da393af

Please sign in to comment.