[lxc-devel] startup scripts for lxc containers?

Michael H. Warfield mhw at WittsEnd.com
Sat Jan 16 03:20:10 UTC 2010


On Sat, 2010-01-16 at 01:03 +0100, Michael Holzt wrote: 
> > Oh, I thought init calls exit after it killed all children.
> 
> No it does not.
> 
> I was thinking about the problem the other day as well. I think some of it
> is already covered by the work of Dietmar. I will describe my ideas in full
> anyway:

> 1. lxc-start opens a pipe.

> 2. As the first process in the container a daemon e.g. lxc-ctld is launched
>    which becomes pid 1. It will fork so that it will become pid 2 also and
>    then in pid 1 a exec to the init binary is done so that init will be pid 
>    1 as it expects. This process keeps one end of the pipe.

I like that idea.

> 3. Now how to detect shutdown or reboot, i had two ideas.

> One is to modify /etc/init.d/halt and /etc/init.d/reboot to send a
>    signal to lxc-ctld. Two different signals, one for halt, one for 
>    reboot.

> Other idea is to just have init-ctl sit there. When it receives sigterm
>    - emitted by init upon shutdown/reboot - it will determine runlevel
>    (0 or 6) and thus know if it is reboot or halt.

> lxc-ctld will signal this to lxc-start through the pipe so that
>    lxc-start now knows what action to take.

> lxc-ctld will not exit on sigterm but wait to be killed through sigkill
>    by init.

Given that these are not totally arbitrary systems, either, once one
know that only the init process remains, you could determine the exiting
runlevel using the runlevel command either from the outer host system
against the guest systems utmp or simply running runlevel within the
context of the container when only init is otherwise left running.
Running "runlevel {lxc.rootfs}/var/run/utmp seems to work very well for
me and would work with Debian, Ubuntu, Fedora, RedHat, and CentOS
systems for sure (I'm playing with them now).  I think some old Unix
systems had utmp in different locations (my Solaris system has it
in /var/adm/utmp) but we are not worried about those cases.  Are there
any cases where we would need to worry about the location or format of
utmp?  Maybe if utmp can't be found, just pull the pin and shut it down
and let the host admin figure out a workaround?

> 4. lxc-start which knows that shutdown or reboot is in progress until
>    lxc-ctld process is no longer in the process table and then kills
>    the init in the container.

That's the key.  Knowing when init is all that's left.

> Problems: We know the "outer" pid of the init in the container but not
> of lxc-ctld. Maybe change argv[0] to make it findable.

> Comments?

> 
> 
> Regards
> Michael
> 

-- 
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: signature.asc
Type: application/pgp-signature
Size: 482 bytes
Desc: This is a digitally signed message part
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20100115/59305d95/attachment.pgp>


More information about the lxc-devel mailing list