Skip to content

Commit

Permalink
snapcraft: provide qemu-external plug connect/disconnect hooks
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
  • Loading branch information
mihalicyn committed Jul 15, 2024
1 parent 8de0a12 commit b4db1b5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
7 changes: 7 additions & 0 deletions snapcraft/commands/daemon.start
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,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"
Expand Down
16 changes: 16 additions & 0 deletions snapcraft/hooks/connect-plug-qemu-external
Original file line number Diff line number Diff line change
@@ -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"
16 changes: 16 additions & 0 deletions snapcraft/hooks/disconnect-plug-qemu-external
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit b4db1b5

Please sign in to comment.