#!/bin/sh
# Return 0 if in a container, 1 if not
# if in a container, also print the container type
if [ -d /run/systemd/system ]; then
type systemd-detect-virt > /dev/null 2>&1 || exit 1
t=`systemd-detect-virt`
case "$t" in
openvz|lxc|lxc-libvirt|systemd-nspawn|docker)
echo $t
exit 0
;;
*)
exit 1
;;
esac
fi
# systemd isn't running, so check upstart
if [ ! -x /sbin/status ]; then
# TODO - we might want to consider detecting in sysvinit or openrc
exit 1
fi
status container-detect 2>/dev/null | grep -q start
if [ $? -eq 0 ]; then
[ -f /run/container_type ] && cat /run/container_type
exit 0
fi
exit 1