[Lxc-users] How to make a container init DIE after finishing runlevel 0

Michael H. Warfield mhw at WittsEnd.com
Mon Jan 25 21:18:07 UTC 2010


On Mon, 2010-01-25 at 21:50 +0100, Daniel Lezcano wrote:

> > apologies for the length, but how is everyone else handling this?
> > this is the last thing i need to solve before i actually start running
> > all my services on this setup.
> >   
> I was wondering if the kernel shouldn't send a signal to the init's 
> parent when sys_reboot is called.

Which still leaves open the question of telling the difference between a
halt and a reboot.  My trick of using the final runlevel
in /var/run/utmp ran a foul over a gotcha in the Debian containers that
they seem to default to mounting tmpfs over /var/run and /var/lock so
you loose that information.  I had to disable "RAMRUN" and "RAMLOCK"
in /etc/default/rcS in the debian images to get around that but I'm not
sure I'm happy doing that.  The alternative examining /var/log/wtmp
didn't work out as reliable.  OpenVZ has a similar problem and it writes
a "reboot" file that can be read but that seems inelegant as well.  I
don't think anything works if someone does a "reboot -f" but I need to
test that condition yet.

To also answer the OP's question.  Here's what I use.  I have a script
that runs periodically in the host.  If the number of processes in a
running container is 1, then I check for the runlevel in
${rootfs}/var/run/utmp.  If that's "? 0" then it's a halt and I run
lxc-stop.  If it's "? 6" then it's a reboot and I stop the container and
then restart it.  I run it every 5 minutes or so or manually.  It runs
fast and could be run more often.  Just sucks polling things like that,
though.  That script, lxc-check, is attached.

Mike
-- 
Michael H. Warfield (AI4NB) | (770) 985-6132 |  mhw at WittsEnd.com
   /\/\|=mhw=|\/\/          | (678) 463-0932 |  http://www.wittsend.com/mhw/
   NIC whois: MHW9          | An optimist believes we live in the best of all
 PGP Key: 0x674627FF        | possible worlds.  A pessimist is sure of it!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lxc-check
Type: application/x-shellscript
Size: 2628 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20100125/4316ede6/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 482 bytes
Desc: This is a digitally signed message part
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20100125/4316ede6/attachment.pgp>


More information about the lxc-users mailing list