Ubuntu Pastebin

Paste from serge at Thu, 9 Apr 2015 18:43:29 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/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
Download as text