Skip to content

Commit

Permalink
Merge pull request #163 from masnax/content-interface-ceph
Browse files Browse the repository at this point in the history
MicroCeph content interface
  • Loading branch information
tomponline authored Sep 26, 2023
2 parents 6a577b9 + ec0f001 commit f25cea7
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 2 deletions.
13 changes: 13 additions & 0 deletions snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions snapcraft/commands/daemon.start
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions snapcraft/hooks/connect-plug-ceph-conf
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions snapcraft/hooks/disconnect-plug-ceph-conf
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f25cea7

Please sign in to comment.