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 Aug 5, 2015
1 parent 7414f4d commit 6c6fc05
Show file tree
Hide file tree
Showing 3 changed files with 74 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 ID of the main process 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.
* **cgroups** Paths to the container's cgroups.
* **externalFds** Paths to the container's open file descriptors.

*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
17 changes: 17 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 @@ -157,3 +160,17 @@ 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 open file descriptors
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 state 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 6c6fc05

Please sign in to comment.