Uploaded image for project: 'Facter'
  1. Facter
  2. FACT-320

PR (630): Add LXC detection to virtual and is_virtual fact - jeffmccune

    Details

    • Type: Task
    • Status: Closed
    • Priority: Normal
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Community
    • Labels:
    • Template:

      Description

      Add LXC detection to virtual and is_virtual fact

      Pull Request Description


      Without this patch the virtual and is_virtual facts are returning "physical" and "false" respectively. This is a problem because Linux Containers are a virtual environment and it is useful to configure things differently in lxc when compared to other virtual environments.

      This patch addresses the problem by detecting if the process is running inside of a linux container by looking at the cgroup entries for the init process. This method is described at http://stackoverflow.com/questions/20010199/determining-if-a-process-runs-inside-lxc-docker#

      Basically, if /proc/1/cgroup looks like this, we're not in a lxc container:

      9:hugetlb:/
      8:perf_event:/
      7:blkio:/
      6:freezer:/
      5:devices:/
      4:memory:/
      3:cpuacct:/
      2:cpu:/
      1:cpuset:/

      But if they look like this then we are in a container:

      9:hugetlb:/lxc/e411045bbbc61eca5d3af7eb0764c30833606f51d20c176f406afbdb47bb04be
      8:perf_event:/lxc/e411045bbbc61eca5d3af7eb0764c30833606f51d20c176f406afbdb47bb04be
      7:blkio:/lxc/e411045bbbc61eca5d3af7eb0764c30833606f51d20c176f406afbdb47bb04be
      6:freezer:/lxc/e411045bbbc61eca5d3af7eb0764c30833606f51d20c176f406afbdb47bb04be
      5:devices:/lxc/e411045bbbc61eca5d3af7eb0764c30833606f51d20c176f406afbdb47bb04be
      4:memory:/lxc/e411045bbbc61eca5d3af7eb0764c30833606f51d20c176f406afbdb47bb04be
      3:cpuacct:/lxc/e411045bbbc61eca5d3af7eb0764c30833606f51d20c176f406afbdb47bb04be
      2:cpu:/lxc/e411045bbbc61eca5d3af7eb0764c30833606f51d20c176f406afbdb47bb04be
      1:cpuset:/lxc/e411045bbbc61eca5d3af7eb0764c30833606f51d20c176f406afbdb47bb04be

      The identifier is the container id and might be useful for a future fact to identify the container Facter is running in.


      (webhooks-id: 47c42247c0ea484cfc888de876700d0f)

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                gepetto-bot gepetto-bot
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Zendesk Support