Ubuntu Pastebin

Paste from serge at Thu, 9 Apr 2015 22:41:33 +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
#!/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
    if type=$(systemd-detect-virt -c); then
        echo $type
        exit 0
    fi
    exit 1
fi

# systemd isn't running, so check upstart
if [ ! -x /sbin/status ]; then
    # TODO - we might want to consider detecting in sysvinit or others
    exit 1
fi
if status container-detect 2>/dev/null | grep -q start; then
    [ -f /run/container_type ] && cat /run/container_type
    exit 0
fi
exit 1
Download as text