Skip to content

Commit 6f99cc3

Browse files
committed
runtime: Split 'create' and 'start' (and add 'delete')
Catch up with opencontainers/runtime-spec@be594153 (Split create and start, 2016-04-01, opencontainers/runtime-spec#384). One benefit of the early-exit 'create' is that the exit code does not conflate container process exits with "failed to setup the sandbox" exits. We can take advantage of that and use non-zero 'create' exits to allow stderr writing (so the runtime can log errors while dying without having to successfully connect to syslog or some such). I still likes the long-running 'create' API because it makes collecting the exit code easier. I've proposed an 'event' operation [1] which would provide a convenient created trigger. With 'event' in place, we don't need the 'create' process exit to serve as that trigger, and could have a long-running 'create' that collects the container process exit code using the portable waitid() family. But the consensus after the 2016-07-13 meeting was to table that while we land docs for the runC API [2], and runC has an early-exit create [3]. The "Callers MAY block..." wording is going to be hard to enforce, but with the runC model, clients rely on the command exits to trigger post-create and post-start activity. The longer the runtime hangs around after completing its action, the laggier those triggers will be. The "MUST NOT attempt to read from its stdin" means a generic caller can safely exec the command with a closed or null stdin, and not have to worry about the command blocking or crashing because of that. The stdout spec for start/delete is more lenient, because runtimes are unlikely to change their behavior because they are unable to write to stdout. If this assumption proves troublesome, we may have to tighten it up later. The ptrace idea in this commit is from Mrunal [4]. [1]: opencontainers/runtime-spec#508 Subject: runtime: Add an 'event' operation for subscribing to pushes [2]: http://ircbot.wl.linuxfoundation.org/meetings/opencontainers/2016/opencontainers.2016-07-13-17.03.log.html#l-15 [3]: opencontainers/runc#827 Summary: Implement create and start [4]: http://ircbot.wl.linuxfoundation.org/eavesdrop/%23opencontainers/%23opencontainers.2016-07-13.log.html#t2016-07-13T18:58:54 Signed-off-by: W. Trevor King <[email protected]>
1 parent 98a6ef6 commit 6f99cc3

File tree

1 file changed

+74
-12
lines changed

1 file changed

+74
-12
lines changed

runtime.md

Lines changed: 74 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,53 +33,91 @@ For example, POSIX systems define [`LANG` and related environment variables][pos
3333

3434
## Commands
3535

36-
### start
36+
### create
3737

38-
Start a container from a [bundle directory][bundle].
38+
[Create][create] a container from a [bundle directory][bundle].
3939

4040
* *Arguments*
4141
* *`<ID>`* Set the container ID to create.
4242
* *Options*
4343
* *`--bundle <PATH>`* Override the path to the [bundle directory][bundle] (defaults to the current working directory).
44-
* *Standard streams:* The runtime MUST attach its standard streams directly to the container process without inspection.
44+
* *Standard streams:*
45+
* *stdin:* The runtime MUST NOT attempt to read from its stdin.
46+
* *stdout:* The handling of stdout is unspecified.
47+
* *stderr:* The runtime MAY print diagnostic messages to stderr, and the format for those lines is not specified in this document.
4548
* *Environment variables*
4649
* *`LISTEN_FDS`:* The number of file descriptors passed.
4750
For example, `LISTEN_FDS=2` would mean that the runtime MUST pass file descriptors 3 and 4 to the container process (in addition to the [standard streams][standard-streams]) to support [socket activation][systemd-listen-fds].
48-
* *Exit code:* The runtime MUST exit with the container process's exit code.
51+
* *Exit code:* Zero if the container was successfully created and non-zero on errors.
52+
53+
Callers MAY block on this command's successful exit to trigger post-create activity.
4954

5055
#### Example
5156

5257
```
5358
# in a bundle directory with a process that echos "hello" and exits 42
59+
$ test -t 1 && echo 'stdout is a terminal'
60+
stdout is a terminal
61+
$ funC create hello-1 <&- >stdout 2>stderr
62+
$ echo $?
63+
0
64+
$ wc stdout
65+
0 0 0 stdout
5466
$ funC start hello-1
67+
$ echo $?
68+
0
69+
$ cat stdout
5570
hello
56-
71+
$ block-on-exit-and-collect-exit-code hello-1
5772
$ echo $?
5873
42
74+
$ funC delete hello-1
75+
$ echo $?
76+
0
5977
```
6078

79+
#### Container process exit
80+
81+
The [example's](#example) `block-on-exit-and-collect-exit-code` is platform-specific and is not specified in this document.
82+
On Linux, it might involve an ancestor process which had set [`PR_SET_CHILD_SUBREAPER`][prctl.2] and collected the container PID [from the state][state], or a process that was [ptracing][ptrace.2] the container process for [`exit_group`][exit_group.2], although both of those race against the container process exiting before the watcher is monitoring.
83+
84+
### start
85+
86+
[Start][start] the user-specified code from [`process`][process].
87+
88+
* *Arguments*
89+
* *`<ID>`* The container to start.
90+
* *Standard streams:*
91+
* *stdin:* The runtime MUST NOT attempt to read from its stdin.
92+
* *stdout:* The handling of stdout is unspecified.
93+
* *stderr:* The runtime MAY print diagnostic messages to stderr, and the format for those lines is not specified in this document.
94+
* *Exit code:* Zero if the container was successfully started and non-zero on errors.
95+
96+
Callers MAY block on this command's successful exit to trigger post-start activity.
97+
98+
See [create](#example) for an example.
99+
61100
### state
62101

63-
Request the container state.
102+
[Request][state-request] the container [state][state].
64103

65104
* *Arguments*
66105
* *`<ID>`* The container whose state is being requested.
67106
* *Standard streams:*
68107
* *stdin:* The runtime MUST NOT attempt to read from its stdin.
69-
* *stdout:* The runtime MUST print the state JSON to its stdout.
108+
* *stdout:* The runtime MUST print the [state JSON][state] to its stdout.
70109
* *stderr:* The runtime MAY print diagnostic messages to stderr, and the format for those lines is not specified in this document.
71110
* *Exit code:* Zero if the state was successfully written to stdout and non-zero on errors.
72111

73112
#### Example
74113

75114
```
76-
# in a bundle directory with a process that sleeps for several seconds
77-
$ funC start sleeper-1 &
115+
$ funC create sleeper-1
78116
$ funC state sleeper-1
79117
{
80118
"ociVersion": "1.0.0-rc1",
81119
"id": "sleeper-1",
82-
"status": "running",
120+
"status": "created",
83121
"pid": 4422,
84122
"bundlePath": "/containers/sleeper",
85123
"annotations" {
@@ -113,8 +151,9 @@ $ echo $?
113151
#### Example
114152

115153
```
116-
# in a bundle directory with a process ignores TERM
117-
$ funC start sleeper-1 &
154+
# in a bundle directory where the container process ignores TERM
155+
$ funC create sleeper-1
156+
$ funC start sleeper-1
118157
$ funC kill sleeper-1
119158
$ echo $?
120159
0
@@ -123,15 +162,38 @@ $ echo $?
123162
0
124163
```
125164

165+
### delete
166+
167+
[Release](#delete) container resources after the container process has exited.
168+
169+
* *Arguments*
170+
* *`<ID>`* The container to delete.
171+
* *Standard streams:*
172+
* *stdin:* The runtime MUST NOT attempt to read from its stdin.
173+
* *stdout:* The handling of stdout is unspecified.
174+
* *stderr:* The runtime MAY print diagnostic messages to stderr, and the format for those lines is not specified in this document.
175+
* *Exit code:* Zero if the container was successfully deleted and non-zero on errors.
176+
177+
See [create](#example) for an example.
178+
126179
[bundle]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/bundle.md
180+
[create]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/runtime.md#create
181+
[delete]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/runtime.md#delete
182+
[exit_group.2]: http://man7.org/linux/man-pages/man2/exit_group.2.html
127183
[kill]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/runtime.md#kill
128184
[kill.2]: http://man7.org/linux/man-pages/man2/kill.2.html
185+
[process]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/config.md#process
129186
[posix-encoding]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap06.html#tag_06_02
130187
[posix-lang]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_02
131188
[posix-locale-encoding]: http://www.unicode.org/reports/tr35/#Bundle_vs_Item_Lookup
132189
[posix-signals]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html#tag_13_42_03
190+
[prctl.2]: http://man7.org/linux/man-pages/man2/prctl.2.html
191+
[ptrace.2]: http://man7.org/linux/man-pages/man2/ptrace.2.html
133192
[semver]: http://semver.org/spec/v2.0.0.html
134193
[standard-streams]: https://github.com/opencontainers/specs/blob/v0.1.1/runtime-linux.md#file-descriptors
194+
[start]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/runtime.md#start
195+
[state]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/runtime.md#state
196+
[state-request]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/runtime.md#query-state
135197
[systemd-listen-fds]: http://www.freedesktop.org/software/systemd/man/sd_listen_fds.html
136198
[runtime-spec-version]: https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc4/config.md#specification-version
137199
[UTF-8]: http://www.unicode.org/versions/Unicode8.0.0/ch03.pdf

0 commit comments

Comments
 (0)