diff --git a/snap/hooks/configure b/snap/hooks/configure index 21800f79..d6d807d2 100644 --- a/snap/hooks/configure +++ b/snap/hooks/configure @@ -36,7 +36,6 @@ config_entries = [ ("flush-interval", "flush_interval", None), ("exchange-interval", "exchange_interval", None), ("apt-update-interval", "apt_update_interval", None), - ("exchange-interval", "exchange_interval", None), ("cloud", "cloud", None), ] @@ -44,7 +43,7 @@ changed = set() for snapctl_key, landscape_key, mapping_fn in config_entries: value = _snapctl("get", snapctl_key).strip() if not value: - # empty, value not has not changed + # empty, value has not changed continue if mapping_fn: diff --git a/snap/hooks/post-refresh b/snap/hooks/post-refresh new file mode 100644 index 00000000..d7c76629 --- /dev/null +++ b/snap/hooks/post-refresh @@ -0,0 +1,26 @@ +#!/bin/sh -e + +# This hook migrates the client's data from $SNAP_DATA to $SNAP_COMMON. +# It will be kept until all the existing +# clients are migrated to $SNAP_COMMON (using this hook). +# Full bug report: https://bugs.launchpad.net/landscape-client/+bug/2082616 + +OLD_DIR="$SNAP_DATA/var/lib/landscape/client" +NEW_DIR="$SNAP_COMMON/var/lib/landscape/client" + +# Is a migration needed? We check if: +# 1. $OLD_DIR exists +# 2. And that we've not already done the migration +if [ -d "$OLD_DIR" ] && [ ! -f "$NEW_DIR/.migrated" ]; then + # Copy files while preserving attributes, links, etc + cp -a "$OLD_DIR/." "$NEW_DIR/" + + # Flush file system buffers, ensuring all pending writes are completed + sync + + # Add migration completion marker + touch "$NEW_DIR/.migrated" + + # Remove the old directory + rm -rf "$OLD_DIR" +fi diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index b58d301f..017d351e 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -10,7 +10,7 @@ description: | in a Landscape account. It provides the Landscape client and requires a Landscape account. -grade: stable # must be 'stable' to release into candidate/stable channels +grade: stable architectures: - build-on: [amd64] - build-on: [arm64] @@ -33,7 +33,7 @@ slots: annotations: interface: content write: - - $SNAP_DATA/var/lib/landscape/client/annotations.d + - $SNAP_COMMON/var/lib/landscape/client/annotations.d apps: landscape-client: @@ -61,11 +61,21 @@ apps: plugs: - network - hardware-observe + +# Previously, the client's data was stored in $SNAP_DATA +# which led to duplicate machine entries after reverting +# to a previous revision. +# After the migration of /var/lib/landscape/client from +# $SNAP_DATA to $SNAP_COMMON, the snap's layout changed. +# The new epoch 1* means the snap can read the previous +# & new epochs' data but can only write epoch 1 data. +epoch: 1* + layout: /etc/landscape-client.conf: bind-file: $SNAP_COMMON/etc/landscape-client.conf /var/lib/landscape/client: - bind: $SNAP_DATA/var/lib/landscape/client + bind: $SNAP_COMMON/var/lib/landscape/client /var/log/landscape: bind: $SNAP_DATA/var/log/landscape