Enhanced detection for LXC and LXC over VM (#426)

* Update functions

* Update functions

* Update tests_shells

* Update tests_shells

* Update IsVirtualMachine

extra check on /proc/1/environ existence + Log result
This commit is contained in:
Stéphane BARBARAY 2017-07-31 12:51:19 +02:00 committed by Michael Boelen
parent 22d76b0d01
commit 9ca2d640b8
1 changed files with 21 additions and 1 deletions

View File

@ -1165,6 +1165,14 @@
EXITCODE=0
fi
fi
if [ -e /proc/1/environ ]; then
FIND=$(grep -qa 'container=lxc' /proc/1/environ)
if [ $? -eq 0 ]; then
LogText "Result: found LXC in environnement (/proc/1/environ), so we are running in LXC container"
CONTAINER_TYPE="LXC"; FOUND=1
EXITCODE=0
fi
fi
if [ ${FOUND} -eq 0 ]; then
CONTAINER_TYPE=""
EXITCODE=1
@ -1331,6 +1339,18 @@
ISVIRTUALMACHINE=2; VMTYPE="unknown"; VMFULLTYPE="Unknown"
SHORT=""
# lxc environ detection
if [ "${SHORT}" = "" ]; then
if [ -f /proc/1/environ ]; then
if grep -qa 'container=lxc' /proc/1/environ; then
SHORT=lxc
LogText "Result: found ${SHORT}"
fi
fi
else
LogText "Result: skipped lxc environ detection test, as we already found machine type"
fi
# facter
if [ "${SHORT}" = "" ]; then
if [ -x /usr/bin/facter ] || [ -x /usr/local/bin/facter ]; then
@ -1371,7 +1391,7 @@
if [ "${SHORT}" = "" ]; then
if [ -x /usr/bin/lscpu ]; then
LogText "Test: trying to guess virtualization with lscpu"
FIND=$(lscpu | grep "^Hypervisor Vendor" | awk -F: '{ print $2 }' | sed 's/ //g')
FIND=$(lscpu | grep -i "^Hypervisor Vendor" | awk -F: '{ print $2 }' | sed 's/ //g')
if [ ! "${FIND}" = "" ]; then
LogText "Result: found ${FIND}"
SHORT="${FIND}"