From f0b5f3aa0627f365f6d0dce6ae60911b483a0208 Mon Sep 17 00:00:00 2001 From: Max Asnaashari Date: Fri, 22 Sep 2023 15:43:28 +0000 Subject: [PATCH 1/3] snapcraft: Add ceph-conf content interface plug Signed-off-by: Max Asnaashari --- snapcraft.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 From 0cc6a04c84cd3f61249bf25ae694dc616caa4dcc Mon Sep 17 00:00:00 2001 From: Max Asnaashari Date: Fri, 22 Sep 2023 15:43:59 +0000 Subject: [PATCH 2/3] snapcraft/hooks: Add interface hooks for ceph-conf Signed-off-by: Max Asnaashari --- snapcraft/hooks/connect-plug-ceph-conf | 37 +++++++++++++++++++++ snapcraft/hooks/disconnect-plug-ceph-conf | 40 +++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100755 snapcraft/hooks/connect-plug-ceph-conf create mode 100755 snapcraft/hooks/disconnect-plug-ceph-conf 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 From ec0f001f246efbefa52a20bec4e6e66cbc155b51 Mon Sep 17 00:00:00 2001 From: Max Asnaashari Date: Fri, 22 Sep 2023 15:44:34 +0000 Subject: [PATCH 3/3] snapcraft/commands: Remove microceph setup from daemon.start Signed-off-by: Max Asnaashari --- snapcraft/commands/daemon.start | 2 -- 1 file changed, 2 deletions(-) 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