github.com/mirantis/virtlet@v1.5.2-0.20191204181327-1659b8a48e9b/images/image_skel/libvirt.sh (about)

     1  #!/bin/bash
     2  set -o errexit
     3  set -o nounset
     4  set -o pipefail
     5  set -o errtrace
     6  
     7  if [[ -f /var/lib/virtlet/config.sh ]]; then
     8    . /var/lib/virtlet/config.sh
     9  fi
    10  
    11  testmode=
    12  if [[ ${1:-} == -testmode ]]; then
    13    testmode=1
    14  fi
    15  
    16  if [[ -f /dind/vmwrapper ]]; then
    17    ln -fs /dind/vmwrapper /vmwrapper
    18  fi
    19  
    20  function regenerate_qemu_conf() {
    21    if ls /sys/class/net/*/device/iommu_group >/dev/null 2>&1 ; then
    22      set $(ls -l /sys/class/net/*/device/iommu_group | sed 's@.*/\(.*\)@"/dev/vfio/\1",@')
    23      sed -i "s|# @DEVS@|$*|" /etc/libvirt/qemu.conf
    24    else
    25      echo WARNING - Virtlet is configured to use SR-IOV but no such resources are available on this host
    26      sed -i "/# @DEVS@/d" /etc/libvirt/qemu.conf
    27    fi
    28  }
    29  
    30  VIRTLET_SRIOV_SUPPORT="${VIRTLET_SRIOV_SUPPORT:-}"
    31  if [[ ${VIRTLET_SRIOV_SUPPORT} ]] ; then
    32    regenerate_qemu_conf
    33  else
    34    sed -i "/# @DEVS@/d" /etc/libvirt/qemu.conf
    35  fi
    36  
    37  chown root:root /etc/libvirt/libvirtd.conf
    38  chown root:root /etc/libvirt/qemu.conf
    39  chmod 644 /etc/libvirt/libvirtd.conf
    40  chmod 644 /etc/libvirt/qemu.conf
    41  
    42  # Without this hack qemu dies trying to unlink
    43  # '/var/lib/libvirt/qemu/capabilities.monitor.sock'
    44  # while libvirt is querying capabilities.
    45  # Removal of the socket below helps but not always.
    46  
    47  if [[ -e /var/lib/libvirt/qemu ]]; then
    48    mv /var/lib/libvirt/qemu /var/lib/libvirt/qemu.ok
    49    mv /var/lib/libvirt/qemu.ok /var/lib/libvirt/qemu
    50  fi
    51  
    52  # export LIBVIRT_LOG_FILTERS="1:qemu.qemu_process 1:qemu.qemu_command 1:qemu.qemu_domain"
    53  # export LIBVIRT_DEBUG=1
    54  
    55  # only make vmwrapper suid in libvirt container
    56  chown root.root /vmwrapper
    57  chmod ug+s /vmwrapper
    58  
    59  if [[ ${testmode} ]]; then
    60    # leftover socket prevents libvirt from initializing correctly
    61    rm -f /var/lib/libvirt/qemu/capabilities.monitor.sock
    62    /usr/sbin/libvirtd --listen --daemon
    63  else
    64    # FIXME: try using exec liveness probe instead
    65    while true; do
    66      /usr/sbin/libvirtd --listen
    67      sleep 1
    68    done
    69  fi