diff --git a/snapcraft/commands/daemon.start b/snapcraft/commands/daemon.start index c65b41574..5dc542d02 100755 --- a/snapcraft/commands/daemon.start +++ b/snapcraft/commands/daemon.start @@ -173,6 +173,13 @@ echo "==> Preparing /run/bin" mkdir -p "/run/bin" export PATH="/run/bin:${PATH}" +if [ -e "${SNAP_COMMON}/use-qemu-external-snap" ]; then + echo "==> Setting up external QEMU snap integration" + export SNAP_QEMU_PREFIX="external/qemu" + LD_LPATH_PIPEWIRE="$(readlink -f "${SNAP_CURRENT}"/${SNAP_QEMU_PREFIX}/lib/"${ARCH}"/pipewire-*/)" + export LD_LIBRARY_PATH="${SNAP_CURRENT}/${SNAP_QEMU_PREFIX}/lib/${ARCH}:${SNAP_CURRENT}/${SNAP_QEMU_PREFIX}/lib/${ARCH}/pulseaudio:${SNAP_CURRENT}/${SNAP_QEMU_PREFIX}/lib/${ARCH}/ceph:${LD_LPATH_PIPEWIRE:+${LD_LPATH_PIPEWIRE}:}${LD_LIBRARY_PATH}" +fi + if [ "${ceph_external:-"false"}" = "true" ]; then ln -s "${SNAP}/wrappers/run-host" "/run/bin/ceph" ln -s "${SNAP}/wrappers/run-host" "/run/bin/radosgw-admin" diff --git a/snapcraft/hooks/connect-plug-qemu-external b/snapcraft/hooks/connect-plug-qemu-external new file mode 100755 index 000000000..fd952af0a --- /dev/null +++ b/snapcraft/hooks/connect-plug-qemu-external @@ -0,0 +1,16 @@ +#!/bin/sh +set -eu + +# Re-exec outside of apparmor confinement +if [ -d /sys/kernel/security/apparmor ]; then + label="$(cat /proc/self/attr/current 2>/dev/null)" + if [ "$label" != "unconfined" ] && [ -n "${label##*(unconfined)}" ]; then + exec aa-exec -p unconfined -- "$0" "$@" + fi +fi + +echo 1 > "${SNAP_COMMON}/use-qemu-external-snap" + +echo reload > "${SNAP_COMMON}/state" +read -r PID < "${SNAP_COMMON}/lxd.pid" +kill "$PID" diff --git a/snapcraft/hooks/disconnect-plug-qemu-external b/snapcraft/hooks/disconnect-plug-qemu-external new file mode 100755 index 000000000..9fce6546f --- /dev/null +++ b/snapcraft/hooks/disconnect-plug-qemu-external @@ -0,0 +1,16 @@ +#!/bin/sh +set -eu + +# Re-exec outside of apparmor confinement +if [ -d /sys/kernel/security/apparmor ]; then + label="$(cat /proc/self/attr/current 2>/dev/null)" + if [ "$label" != "unconfined" ] && [ -n "${label##*(unconfined)}" ]; then + exec aa-exec -p unconfined -- "$0" "$@" + fi +fi + +rm -f "${SNAP_COMMON}/use-qemu-external-snap" + +echo reload > "${SNAP_COMMON}/state" +read -r PID < "${SNAP_COMMON}/lxd.pid" +kill "$PID"