Skip to content

Commit 180df9d

Browse files
author
Michael Crosby
committed
Add runtime state configuration and structs
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 <[email protected]>
1 parent 138deee commit 180df9d

3 files changed

Lines changed: 44 additions & 0 deletions

File tree

config.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,15 @@ type MountPoint struct {
5656
// Path specifies the path of the mount. The path and child directories MUST exist, a runtime MUST NOT create directories automatically to a mount point.
5757
Path string `json:"path"`
5858
}
59+
60+
// State holds information about the runtime state of the container.
61+
type State struct {
62+
// Version is the version of the specification that is supported.
63+
Version string `json:"version"`
64+
// ID is the container ID
65+
ID string `json:"id"`
66+
// Pid is the process id for the container's main process.
67+
Pid int `json:"pid"`
68+
// Root is the path to the container's bundle directory.
69+
Root string `json:"root"`
70+
}

runtime.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
11
# Runtime and Lifecycle
22

3+
## State
4+
5+
The runtime state for a container is persisted on disk so that external tools can consume and act on this information.
6+
The runtime state is stored in a JSON encoded file.
7+
It is recommended that this file is stored in a temporary filesystem so that it can be removed on a system reboot.
8+
On Linux based systems the state information should be stored in `/run/oci/containers`.
9+
The directory structure for a container is `/run/oci/containers/<containerID>/state.json`.
10+
By providing a default location that container state is stored external applications can find all containers running on a system.
11+
12+
* **version** (string) Version of the OCI specification used when creating the container.
13+
* **id** (string) ID is the container's ID.
14+
* **pid** (int) Pid is the ID of the main process within the container.
15+
* **root** (string) Root is the path to the container's bundle directory.
16+
17+
The ID is provided in the state because hooks will be executed with the state as the payload.
18+
This allows the hook to perform clean and teardown logic after the runtime destroys its own state.
19+
20+
The root directory to the bundle is provided in the state so that consumers can find the container's configuration and rootfs where it is located on the host's filesystem.
21+
22+
*Example*
23+
24+
```json
25+
{
26+
"id": "oci-container",
27+
"pid": 4422,
28+
"root": "/containers/redis"
29+
}
30+
```
31+
332
## Lifecycle
433

534
### Create

runtime_config_linux.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package specs
22

33
import "os"
44

5+
// LinuxStateDirectory holds the container's state information
6+
const LinuxStateDirectory = "/run/oci/containers"
7+
58
// LinuxRuntimeSpec is the full specification for linux containers.
69
type LinuxRuntimeSpec struct {
710
RuntimeSpec

0 commit comments

Comments
 (0)