[lxc-devel] Getting some hooks into the container configuration

Stéphane Graber stgraber at ubuntu.com
Fri May 25 13:53:01 UTC 2012


On 05/25/2012 04:17 AM, Matthijs Kooijman wrote:
> Hi Stéphane,
> 
>>  - stop: Is run after the container died
>> [...]
>> Potential other hooks include pre-start and post-stop
> What would be the difference between stop and post-stop, if stop also
> runs _after_ the container died?
> 
> Gr.
> 
> Matthijs

It'd be run after the umount has been done.

But that got me to go and read the OpenVZ definition of these and made
me catch a "small" detail I had missed.

The start and stop hooks in OpenVZ are actually run in the container's
namespaces.

Basically the timeline would be:
 - HOOK: pre-start (host namespace)
 - LXC: mount rootfs and fstab entries
 - HOOK: mount (host namespace)
 - LXC: spawn init
 - HOOK: start (container namespace)
 - USER: do whatever they want in the container
 - LXC: stops the container
 - HOOK: stop (container namespace)
 - LXC: kill the container
 - HOOK: umount (host namespace)
 - LXC: umount rootfs and fstab entries
 - HOOK: post-stop (host namespace)

Based on OpenVZ documentation, if we aim at implementing something
similar, then:
 - "start" would be run inside the container (but script lives outside
of it) and called right before init is spawned.
 - "stop" would be run inside the container (but script lives outside of
it) and called right after init dies.

I must admit never having used these two and I'm a bit unsure whether
they are really that useful and whether we can even implement them with
the current state of things.


Something else I didn't mention in my original post is the behavior on
exit failure for the hooks. OpenVZ typically treats any non-zero return
code as a failure and tries to kill the container but without calling
any additional hook.
For example, a failure in the "start" hook will cause the container to
be shutdown and unmounted but without calling the stop, umount or
post-stop hooks.

(I'm mostly looking at
http://download.openvz.org/doc/OpenVZ-Users-Guide.pdf in the "OpenVZ
Action Scripts" section)


-- 
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 900 bytes
Desc: OpenPGP digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20120525/c6dbc113/attachment.pgp>


More information about the lxc-devel mailing list