Skip to content

Commit

Permalink
hooks: deduplicate the hooks docs
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
  • Loading branch information
vbatts committed Sep 25, 2015
1 parent f25012f commit 25cdae2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 47 deletions.
50 changes: 48 additions & 2 deletions runtime-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,55 @@
Lifecycle of a container's runtime, for setup and teardown.
Presently there are `Prestart` and `Poststop`.

* `Prestart` is a list of hooks to be run before the container process is executed
* `Poststop` is a list of hooks to be run after the container process exits
* [`Prestart`](#pre-start) is a list of hooks to be run before the container process is executed
* [`Poststop`](#post-stop)is a list of hooks to be run after the container process exits

Hooks allow one to run code before/after various lifecycle events of the container.
Hooks MUST be called in the listed order.
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* object.
Expand Down
46 changes: 1 addition & 45 deletions runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,48 +49,4 @@ 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.
Hooks MUST be called in the listed order.
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.
See [runtime configuration for hooks](./runtime-config.md)

0 comments on commit 25cdae2

Please sign in to comment.