diff --git a/snapcraft.yaml b/snapcraft.yaml index 5943a8616..0ef1d3ae9 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -59,6 +59,11 @@ source-code: https://github.com/canonical/lxd website: https://ubuntu.com/lxd confinement: strict +plugs: + ceph-conf: + interface: content + target: "$SNAP_DATA/microceph" + apps: # Main commands activate: @@ -141,6 +146,14 @@ apps: - system-observe hooks: + connect-plug-ceph-conf: + plugs: + - lxd-support + - system-observe + disconnect-plug-ceph-conf: + plugs: + - lxd-support + - system-observe configure: plugs: - lxd-support diff --git a/snapcraft/commands/daemon.start b/snapcraft/commands/daemon.start index 8622927bd..188a6f8c3 100755 --- a/snapcraft/commands/daemon.start +++ b/snapcraft/commands/daemon.start @@ -295,8 +295,6 @@ echo "==> Setting up ceph configuration" if [ "${ceph_builtin:-"false"}" = "true" ]; then mkdir -p "${SNAP_COMMON}/ceph" ln -s "${SNAP_COMMON}/ceph" /etc/ceph -elif [ -e "/var/snap/microceph" ]; then - ln -s /var/snap/microceph/current/conf/ /etc/ceph else ln -s /var/lib/snapd/hostfs/etc/ceph /etc/ceph fi diff --git a/snapcraft/hooks/connect-plug-ceph-conf b/snapcraft/hooks/connect-plug-ceph-conf new file mode 100755 index 000000000..edd8ab8cf --- /dev/null +++ b/snapcraft/hooks/connect-plug-ceph-conf @@ -0,0 +1,37 @@ +#!/bin/sh +set -eu + +# Re-exec outside of apparmor confinement +if [ -d /sys/kernel/security/apparmor ] && [ "$(cat /proc/self/attr/current)" != "unconfined" ]; then + exec aa-exec -p unconfined -- "$0" "$@" +fi + +# Utility functions +get_bool() { + value=$(echo "${1:-}" | tr '[:upper:]' '[:lower:]') + + # See if it's true + for yes in "true" "1" "yes" "on"; do + if [ "${value}" = "${yes}" ]; then + echo "true" + return + fi + done + + # See if it's false + for no in "false" "0" "no" "off"; do + if [ "${value}" = "${no}" ]; then + echo "false" + return + fi + done + + # Invalid value (or not set) + return +} + +ceph_builtin=$(get_bool "$(snapctl get ceph.builtin)") + +if ! [ "${ceph_builtin:-"false"}" = "true" ]; then + ln -snf ${SNAP_DATA}/microceph/conf/ /etc/ceph +fi diff --git a/snapcraft/hooks/disconnect-plug-ceph-conf b/snapcraft/hooks/disconnect-plug-ceph-conf new file mode 100755 index 000000000..6df9ed9bf --- /dev/null +++ b/snapcraft/hooks/disconnect-plug-ceph-conf @@ -0,0 +1,40 @@ +#!/bin/sh +set -eu + +# Re-exec outside of apparmor confinement +if [ -d /sys/kernel/security/apparmor ] && [ "$(cat /proc/self/attr/current)" != "unconfined" ]; then + exec aa-exec -p unconfined -- "$0" "$@" +fi + +# Utility functions +get_bool() { + value=$(echo "${1:-}" | tr '[:upper:]' '[:lower:]') + + # See if it's true + for yes in "true" "1" "yes" "on"; do + if [ "${value}" = "${yes}" ]; then + echo "true" + return + fi + done + + # See if it's false + for no in "false" "0" "no" "off"; do + if [ "${value}" = "${no}" ]; then + echo "false" + return + fi + done + + # Invalid value (or not set) + return +} + +ceph_builtin=$(get_bool "$(snapctl get ceph.builtin)") + +if [ "${ceph_builtin:-"false"}" = "true" ]; then + mkdir -p "${SNAP_COMMON}/ceph" + ln -snf "${SNAP_COMMON}/ceph" /etc/ceph +else + ln -snf /var/lib/snapd/hostfs/etc/ceph /etc/ceph +fi