Free Hosting Online for WorkStations

< Previous | Contents | Next >

6.12. Lifecycle management hooks


Beginning with Ubuntu 12.10, it is possible to define hooks to be executed at specific points in a container's lifetime:

• Pre-start hooks are run in the host's namespace before the container ttys, consoles, or mounts are up. If any mounts are done in this hook, they should be cleaned up in the post-stop hook.

• Pre-mount hooks are run in the container's namespaces, but before the root filesystem has been mounted. Mounts done in this hook will be automatically cleaned up when the container shuts down.

• Mount hooks are run after the container filesystems have been mounted, but before the container has called

pivot_root to change its root filesystem.

• Start hooks are run immediately before executing the container's init. Since these are executed after pivoting into the container's filesystem, the command to be executed must be copied into the container's filesystem.

• Post-stop hooks are executed after the container has been shut down.


If any hook returns an error, the container's run will be aborted. Any post-stop hook will still be executed. Any output generated by the script will be logged at the debug priority.


Please see the lxc.container.conf manual page for the configuration file format with which to specify hooks. Some sample hooks are shipped with the lxc package to serve as an example of how to write and use such hooks.


Top OS Cloud Computing at OnWorks: