Skip to content

Commit 7152193

Browse files
committed
command-line-interface: Split create and start
Catch up with be59415 (Split create and start, 2016-04-01, opencontainers#384). I'm not a big fan of this early-exit 'create', which requires platform-specific magic to collect the container process's exit code. I have a proposal for 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 this week's meeting was to table that while we land docs for the runC API [2]. The "SHOULD exit as quickly as possible after ..." wording is going to be hard to enforce (which is why it's not MUST), 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 'create' ID argument is required (while the old 'start' ID argument was optional) because the runC approach requires an explicit 'delete' call to cleanup the container. With a long-running 'create' that could automatically cleanup, you could have an optional ID to support users that don't care what ID is used (because they know they won't be calling 'state', 'start', etc.). 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). 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 is from Mrunal [3]. [1]: opencontainers#508 [2]: http://ircbot.wl.linuxfoundation.org/meetings/opencontainers/2016/opencontainers.2016-07-13-17.03.log.html#l-15 [3]: 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 a21b162 commit 7152193

File tree

1 file changed

+66
-8
lines changed

1 file changed

+66
-8
lines changed

command-line-interface.md

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,31 +45,68 @@ $ echo $?
4545
0
4646
```
4747

48-
### start
48+
### create
4949

50-
[Start][start] a container from a [bundle directory][bundle].
50+
[Create][create] a container from a [bundle directory][bundle].
51+
This command SHOULD exit as quickly as possible after creating the container, without waiting for the container process to exit.
5152

53+
* *Arguments*
54+
* *`<ID>`* Set the container ID to create.
5255
* *Options*
53-
* *`--id <ID>`* Set the container ID when creating a container.
54-
If not set, the runtime is free to pick any ID that is not already in use.
5556
* *`--bundle <PATH>`* Override the path to the [bundle directory][bundle] (defaults to the current working directory).
56-
* *Standard streams:* The runtime MUST attach its standard streams directly to the container process without inspection.
57+
* *Standard streams:*
58+
* *stdin:* The runtime MUST attach its stdin directly to the container process without reading from it.
59+
* *stdout:* The runtime MUST attach its stdout directly to the container process without writing to it.
60+
* *stderr:* The runtime MUST attach its stderr to the container process, and MUST not write to it unless it exits with a non-zero code.
5761
* *Environment variables*
5862
* *`LISTEN_FDS`:* The number of file descriptors passed.
5963
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) to support [socket activation][systemd-listen-fds].
60-
* *Exit code:* The runtime MUST exit with the container process's exit code.
64+
* *Exit code:* Zero if the container was successfully created and non-zero on errors.
6165

6266
#### Example
6367

6468
```
6569
# in a bundle directory with a process that echos "hello" and exits 42
66-
$ funC start --id hello-1
70+
$ test -t 1 && echo 'stdout is a terminal'
71+
stdout is a terminal
72+
$ funC create hello-1
73+
$ echo $?
74+
0
75+
$ funC start hello-1
6776
hello
68-
77+
$ echo $?
78+
0
79+
$ block-on-exit-and-collect-exit-code hello-1
6980
$ echo $?
7081
42
82+
$ funC delete hello-1
83+
$ echo $?
84+
0
7185
```
7286

87+
`hello` shows up on in the terminal after `start`, because `start` happens to be called from the same shell session (using the same terminal) as `create`, and the container process inherited its standard streams from `create`.
88+
If you call `start` from a shell using a separate terminal, the container output would still have appeared in the `create` terminal.
89+
90+
#### Container process exit
91+
92+
The [example's](#example-1) `block-on-exit-and-collect-exit-code` is platform-specific magic that is not specified in this document.
93+
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.
94+
95+
### start
96+
97+
[Start][start] the user-specified code from [`process`][process].
98+
This command SHOULD exit as quickly as possible after triggering the execution, without waiting for the container process to exit.
99+
100+
* *Arguments*
101+
* *`<ID>`* Set the container ID to start.
102+
* *Standard streams:*
103+
* *stdin:* The runtime MUST NOT attempt to read from its stdin.
104+
* *stdout:* The handling of stdout is unspecified.
105+
* *stderr:* The runtime MAY print diagnostic messages to stderr, and the format for those lines is not specified in this document.
106+
* *Exit code:* Zero if the container was successfully started and non-zero on errors.
107+
108+
See [create](#example-1) for an example.
109+
73110
### state
74111

75112
[Request][state-request] the container [state][state].
@@ -135,14 +172,35 @@ $ echo $?
135172
0
136173
```
137174

175+
### delete
176+
177+
[Release](#delete) container resources after the container process has exited.
178+
179+
* *Arguments*
180+
* *`<ID>`* Set the container ID to delete.
181+
* *Standard streams:*
182+
* *stdin:* The runtime MUST NOT attempt to read from its stdin.
183+
* *stdout:* The handling of stdout is unspecified.
184+
* *stderr:* The runtime MAY print diagnostic messages to stderr, and the format for those lines is not specified in this document.
185+
* *Exit code:* Zero if the container was successfully deleted and non-zero on errors.
186+
187+
See [create](#example-1) for an example.
188+
138189
[bundle]: bundle.md
190+
[create]: runtime.md#create
191+
[delete]: runtime.md#delete
192+
[exit_group.2]: http://man7.org/linux/man-pages/man2/exit_group.2.html
139193
[kill]: runtime.md#kill
140194
[kill.2]: http://man7.org/linux/man-pages/man2/kill.2.html
195+
[process]: config.md#process-configuration
141196
[posix-encoding]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap06.html#tag_06_02
142197
[posix-lang]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_02
143198
[posix-locale-encoding]: http://www.unicode.org/reports/tr35/#Bundle_vs_Item_Lookup
144199
[posix-signals]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html#tag_13_42_03
200+
[prctl.2]: http://man7.org/linux/man-pages/man2/prctl.2.html
201+
[ptrace.2]: http://man7.org/linux/man-pages/man2/ptrace.2.html
145202
[runtime]: glossary.md#runtime
203+
[standard-streams]: https://github.com/opencontainers/specs/blob/v0.1.1/runtime-linux.md#file-descriptors
146204
[start]: runtime.md#start
147205
[state]: runtime.md#state
148206
[state-request]: runtime.md#query-state

0 commit comments

Comments
 (0)