Hi Linuxcontainers.org, :)

this is my first post to this list and I just wanted to reply to a post
https://lists.linuxcontainers.org/pipermail/lxc-users/2016-August/012083.html.


Because I just subscribed to the list, I can not reply to that post, so
here is a short script
I've been using and it seems to be working ok in LXC/LXD envs that I'm on.

---------------
#!/bin/bash
#####################################################################
## _Bash function to determine the 'host_role'
# Check whether we are a LXC-container or not (i.e host)?
# - = (no args)
# - return (echo): 0 = not container/host, 1 = LXC-container
## Author: Jukka Aaltonen, Koha-Lappi -migration project
#####################################################################
function _host-role {
    rc=0
    host_role="Host/platform"

    ## Check whether we are a LXC-container
    sudo grep -qa "container=lxc" /proc/1/environ
    if [[ $? -eq 0 ]]; then
        host_role="LXC-container"; rc=1
    else
        host_role="Host/platform"; rc=0
    fi
    echo "Hostname (LXC-guest/host):$(hostname) ($host_role)"

    return $rc
}
---------------

HTH

-jukka
_______________________________________________
lxc-users mailing list
[email protected]
http://lists.linuxcontainers.org/listinfo/lxc-users

Reply via email to