Issue #4995 has been updated by Krzysztof Wilczynski.

Krzysztof Wilczynski wrote:
> Jonas Genannt wrote:
> > > My take on this: 
> > > [lxc.rb](https://raw.github.com/kwilczynski/facter-facts/master/lxc.rb); 
> > > in the repository: 
> > > [facter-facts](https://github.com/kwilczynski/facter-facts).
> > > 
> > > I tested it using multiple versions of LXC and "liblxc", plus few 
> > > different versions of "libvirt" (why do they change so much between 
> > > releases?!) and I do hope that everything works as it says on the tin :-)
> > > 
> > > What needs doing: consolidating it under the "virtual" fact which was 
> > > also done and I need to give it just a little bit more attention, and as 
> > > usual I need to write tests for it ... :)
> > 
> > great. I had to add require 'thread' at the top, to get it working.
> 
> Already added, well spotted :) I must have deleted this by accident ... 
> somehow?! :)
> 
> > The fact reports host on my lxc master system - that correct.
> 
> Good to know.
> 
> > On my lxc container with Debian Squeeze 2.6.32-5-amd64 with lxc 0.7.3-1 the 
> > fact does not work.
> 
> > The output of "cat /proc/1/environ" returns "_=./lxc"
> > 
> > There is no "container="
> 
> I will look into this. Could you run this one for me and paste output either 
> here or mail me directly :)
> 
> [...]
> 
> Also, how do you create a container? I see that you are using native LXC 
> utilities ... Unless something has changed there should be "container=" 
> there. I will look at the source code of this particular version (0.7.3) and 
> see what is going on there :-) What is your host system? Debian? Ubuntu?
> 
> P.S. If you are on IRC, you can grab me on Freenode ... I am as "matti" there 
> on #puppet and ##devops.
> 
> KW

Right. Quick look at the Linux Containers git repository reveals the following:

<pre>
diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c
index 661764a..4f3d964 100644
--- a/src/lxc/lxc_start.c
+++ b/src/lxc/lxc_start.c
@@ -117,6 +117,11 @@ int main(int argc, char *argv[])
                         my_args.progname, my_args.quiet))
                return err;
 
+       if (putenv("container=lxc")) {
+               SYSERROR("failed to set environment variable");
+               return err;
+       }
+
        /* rcfile is specified in the cli option */
        if (my_args.rcfile)
                rcfile = (char *)my_args.rcfile;


</pre>

This was added:

<pre>
commit 3244e75040a98d2854144ebc169a5a61ddbe0a26
Author: Daniel Lezcano <[email protected]>
Date:   Fri Jan 28 00:14:51 2011 +0100

    export env variable in lxc_start

</pre>

Sadly, this was after Daniel tagged version 0.7.3 :-(

Therefore, we have to add additional check vector to detect older versions: 
check whether external command (the "_" variable) matches "lxc", "lxc-start" or 
"lxc-exec", plus additionally we could have a peek at "PWD" passed down to 
"init" as it may show something like "/var/lib/lxc/test" etc ...

KW
----------------------------------------
Feature #4995: LXC Container support
https://projects.puppetlabs.com/issues/4995

Author: Jonas Genannt
Status: Investigating
Priority: Low
Assignee: Krzysztof Wilczynski
Category: library
Target version: 
Keywords: virtual,lxc
Branch: 
Affected Facter version: 


The virtual fact for facter should support lxc containers.

For more information about lxc: http://lxc.sourceforge.net/

We can detect an running lxc master system, if /cgroup is mounted on the system.




-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://projects.puppetlabs.com/my/account

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Bugs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-bugs?hl=en.

Reply via email to