-
Notifications
You must be signed in to change notification settings - Fork 597
hooks: start with pre-start and post-stop hooks. #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,3 +15,45 @@ Runs a process in a container. Can be invoked several times. | |
| Not sure we need that from runc cli. Process is killed from the outside. | ||
|
|
||
| This event needs to be captured by runc to run onstop event handlers. | ||
|
|
||
| ## Hooks | ||
| Hooks allow one to run code before/after various lifecycle events of the container. | ||
| The state of the container is passed to the hooks over stdin, so the hooks could get the information they need to do their work. | ||
|
|
||
| Hook paths are absolute and are executed from the host's filesystem. | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also specify and provide an example of the payload that it sent to stdin
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can provide an example. However, does it make sense to standardize what all is passed? WDYT? |
||
| ### Pre-start | ||
| The pre-start hooks are called after the container process is spawned, but before the user supplied command is executed. | ||
| They are called after the container namespaces are created on Linux, so they provide an opportunity to customize the container. | ||
| In Linux, for e.g., the network namespace could be configured in this hook. | ||
|
|
||
| If a hook returns a non-zero exit code, then an error including the exit code and the stderr is returned to the caller and the container is torn down. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't mention
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @LK4D4 I think I did mention it :) |
||
|
|
||
| ### Post-stop | ||
| The post-stop hooks are called after the container process is stopped. Cleanup or debugging could be performed in such a hook. | ||
| If a hook returns a non-zero exit code, then an error is logged and the remaining hooks are executed. | ||
|
|
||
| *Example* | ||
|
|
||
| ```json | ||
| "hooks" : { | ||
| "prestart": [ | ||
| { | ||
| "path": "/usr/bin/fix-mounts", | ||
| "args": ["arg1", "arg2"], | ||
| "env": [ "key1=value1"] | ||
| }, | ||
| { | ||
| "path": "/usr/bin/setup-network" | ||
| } | ||
| ], | ||
| "poststop": [ | ||
| { | ||
| "path": "/usr/sbin/cleanup.sh", | ||
| "args": ["-f"] | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| `path` is required for a hook. `args` and `env` are optional. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we document what's the expected format of the input ? (i.e. all of state.json)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will document that once we finalize the format which is being discussed in other issues.