Skip to content

Commit

Permalink
Move hooks from lifecycle.md to runtime.md
Browse files Browse the repository at this point in the history
Hooks are only valid in runtime.json, so we should discuss them in the
runtime.json docs.  I'll add appropriate links from the lifecycle docs
in a bit, but linking into runtime.json is poor enough that I think it
deserves its own commit.  The only change here besides the copy/paste
is the addition of a blank line after the Markdown headers to match
the rest of the documentation.

Signed-off-by: W. Trevor King <wking@tremily.us>
  • Loading branch information
wking committed Aug 30, 2015
1 parent 4d30c41 commit 4cfa584
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 42 deletions.
42 changes: 0 additions & 42 deletions lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,3 @@ 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.

### 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.

### 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.
45 changes: 45 additions & 0 deletions runtime.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
## 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.

### 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.

### 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.

## Mount Configuration

Additional filesystems can be declared as "mounts", specified in the *mounts* array. The parameters are similar to the ones in Linux mount system call. [http://linux.die.net/man/2/mount](http://linux.die.net/man/2/mount)
Expand Down

0 comments on commit 4cfa584

Please sign in to comment.