From d4afa140fc426c6ecb9e4b58c0cb862b25cec970 Mon Sep 17 00:00:00 2001 From: Simon Deziel Date: Fri, 22 Sep 2023 14:47:45 -0400 Subject: [PATCH 1/5] lxd-migrate/lxd: Ubuntu 18.04 and 16.04 are EOL Signed-off-by: Simon Deziel --- lxd-migrate/lxd.go | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/lxd-migrate/lxd.go b/lxd-migrate/lxd.go index 5d30a3ac3..3cfe68edc 100644 --- a/lxd-migrate/lxd.go +++ b/lxd-migrate/lxd.go @@ -284,29 +284,6 @@ func (d *lxdDaemon) uninstall() error { return err } - // Check if we can get rid of liblxc1, liblxc-common and lxcfs too - //// Ubuntu 18.04 - err = packagesRemovable([]string{"liblxc1", "liblxc-common", "lxcfs"}) - if err == nil { - _, err := shared.RunCommand("apt-get", "remove", "--purge", "--yes", "liblxc1", "liblxc-common", "lxcfs") - if err != nil { - return err - } - - return nil - } - - //// Ubuntu 16.04 - err = packagesRemovable([]string{"liblxc1", "lxc-common", "lxcfs"}) - if err == nil { - _, err := shared.RunCommand("apt-get", "remove", "--purge", "--yes", "liblxc1", "lxc-common", "lxcfs") - if err != nil { - return err - } - - return nil - } - return nil } From 76005b9541d85cd498cdd63cd168cbc42e7d7428 Mon Sep 17 00:00:00 2001 From: Simon Deziel Date: Fri, 22 Sep 2023 14:53:40 -0400 Subject: [PATCH 2/5] lxd-migrate/main: Drop lxd-bridge bits dating from LXD 2.0 Signed-off-by: Simon Deziel --- lxd-migrate/main.go | 49 --------------------------------------------- 1 file changed, 49 deletions(-) diff --git a/lxd-migrate/main.go b/lxd-migrate/main.go index 2072e5695..052e1605e 100644 --- a/lxd-migrate/main.go +++ b/lxd-migrate/main.go @@ -80,17 +80,6 @@ func run() error { if err == nil { fmt.Printf("The source server is empty, no migration needed.\n") - if shared.PathExists("/usr/lib/lxd/lxd-bridge") { - shared.RunCommand("/usr/lib/lxd/lxd-bridge", "stop") - - if shared.PathExists("/etc/default/lxd-bridge") { - _, err = shared.RunCommand("mv", "/etc/default/lxd-bridge", "/etc/default/lxd-bridge.migrated") - if err != nil { - return fmt.Errorf("Failed to move the bridge configuration: %v", err) - } - } - } - return removePackages(src, dst) } @@ -202,21 +191,6 @@ func run() error { return fmt.Errorf("Failed to update the storage pools: %v", err) } - // Copy the network config - if src.networks == nil && dst.networks == nil { - fmt.Printf("=> Moving bridge configuration\n") - - // Atempt to stop lxd-bridge - systemdCtl("stop", "lxd-bridge") - - if shared.PathExists("/etc/default/lxd-bridge") { - _, err = shared.RunCommand("mv", "/etc/default/lxd-bridge", "/var/snap/lxd/common/lxd-bridge/config") - if err != nil { - return fmt.Errorf("Failed to move the bridge configuration: %v", err) - } - } - } - // Start the destination LXD fmt.Printf("=> Starting the destination LXD\n") err = dst.start() @@ -238,29 +212,6 @@ func run() error { return err } - if src.networks == nil && dst.networks != nil { - // Update the network configuration - fmt.Printf("=> Converting the network configuration\n") - _, err = shared.RunCommand("upgrade-bridge") - if err != nil { - return fmt.Errorf("Failed to convert the network configuration: %v", err) - } - - // Reload LXD post-update (to re-create the bridge if needed) - fmt.Printf("=> Reloading LXD after network update\n") - err = dst.reload() - if err != nil { - return err - } - - // Wait for LXD to be online - fmt.Printf("=> Waiting for LXD to come online\n") - err = dst.wait(false) - if err != nil { - return err - } - } - // Show the updated destination server fmt.Printf("\n=== Destination server\n") err = dst.update() From 5c78a1af2752eec9da1e5a725dc6ed6a6302de89 Mon Sep 17 00:00:00 2001 From: Simon Deziel Date: Fri, 22 Sep 2023 14:56:01 -0400 Subject: [PATCH 3/5] snapcraft: stop installing upgrade-bridge script Signed-off-by: Simon Deziel --- snapcraft.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/snapcraft.yaml b/snapcraft.yaml index 0ef1d3ae9..66c76d023 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -1493,12 +1493,9 @@ parts: # Build the binaries go build -o "${CRAFT_PART_INSTALL}/bin/lxd-migrate" -tags=libsqlite3 ./ - # Install bridge script mkdir -p ${CRAFT_PART_INSTALL}/bin/ - cp scripts/upgrade-bridge ${CRAFT_PART_INSTALL}/bin/upgrade-bridge prime: - bin/lxd-migrate - - bin/upgrade-bridge lxd-ui: source: https://github.com/canonical/lxd-ui From 2f6365c7b66e1dc9f45bef719c4ca47f9ba08dfe Mon Sep 17 00:00:00 2001 From: Simon Deziel Date: Fri, 22 Sep 2023 14:56:40 -0400 Subject: [PATCH 4/5] lxd-migrate: Drop upgrade-bridge script (remnant of LXD 2.0) Signed-off-by: Simon Deziel --- lxd-migrate/scripts/upgrade-bridge | 151 ----------------------------- 1 file changed, 151 deletions(-) delete mode 100755 lxd-migrate/scripts/upgrade-bridge diff --git a/lxd-migrate/scripts/upgrade-bridge b/lxd-migrate/scripts/upgrade-bridge deleted file mode 100755 index f4d28a9a7..000000000 --- a/lxd-migrate/scripts/upgrade-bridge +++ /dev/null @@ -1,151 +0,0 @@ -#!/bin/sh -set -e -# Work from the snap -export PATH=/snap/bin/:${PATH} -export LANG=C.UTF-8 - -# Functions -maskcidr() { - local x=${1##*255.} - set -- 0^^^128^192^224^240^248^252^254^ $(( (${#1} - ${#x})*2 )) ${x%%.*} - x=${1%%$3*} - echo $(( $2 + (${#x}/4) )) -} - -# Skip if already converted -if [ ! -e /etc/default/lxd-bridge ]; then - echo "LXD bridge already converted" - exit 0 -fi - -# Source current configuration -. /etc/default/lxd-bridge - -# Setup temporary config dir -export LXD_CONF=$(mktemp -d) - -# Check if LXD is functional (chroot detection) -if ! lxc info --force-local >/dev/null 2>&1; then - echo "This system isn't running LXD, assuming stock configuration." - mv /etc/default/lxd-bridge /etc/default/lxd-bridge.upgraded - - echo "Cleaning up lxd-bridge state files" - rm -Rf /var/lib/lxd-bridge /run/lxd-bridge "${LXD_CONF}" - exit 0 -fi - -# Clear deprecated settings -echo "Unsetting deprecated profile options" -lxc profile unset default user.network_mode --force-local || true -lxc profile unset default environment.http_proxy --force-local || true - -# Done for unconfigured bridges -if [ "${USE_LXD_BRIDGE}" != "true" ] || [ -z "${LXD_BRIDGE}" ]; then - echo "No bridge configuration to convert" - mv /etc/default/lxd-bridge /etc/default/lxd-bridge.upgraded - - echo "Cleaning up lxd-bridge state files" - rm -Rf /var/lib/lxd-bridge /run/lxd-bridge "${LXD_CONF}" - exit 0 -fi - -# Attempting to kill existing lxd-bridge -echo "Attempting to kill current lxd-bridge" -if [ -e "/run/systemd/system" ] && systemctl -q is-active lxd-bridge; then - systemctl stop lxd-bridge || true -fi - -if [ -e "/run/lxd-bridge/network_up" ] && [ -e "/usr/lib/lxd/lxd-bridge" ]; then - /usr/lib/lxd/lxd-bridge stop || true -fi - -if [ -e "/run/lxd-bridge/dnsmasq.pid" ]; then - kill -9 "$(cat /run/lxd-bridge/dnsmasq.pid)" >/dev/null 2>&1 || true -fi - -# Check if the bridge exists -EXISTING=false -if [ -e "/sys/class/net/${LXD_BRIDGE}" ]; then - EXISTING=true -fi - -# Check for stock installation -if [ "${EXISTING}" = "false" ] && [ "$(md5sum /etc/default/lxd-bridge | cut -d' ' -f1)" = "e8cfb4997d9443fe48302bb75326b09f" ]; then - echo "Stock LXD installation detected, resetting to new defaults" - lxc profile device remove default eth0 --force-local >/dev/null 2>&1 || true - mv /etc/default/lxd-bridge /etc/default/lxd-bridge.upgraded - - echo "Cleaning up lxd-bridge state files" - rm -Rf /var/lib/lxd-bridge /run/lxd-bridge "${LXD_CONF}" - exit 0 -fi - -# Bring down and rename an existing bridge -if [ "${EXISTING}" = "true" ]; then - if [ -e "/sys/class/net/lxd-upgrade" ]; then - ip link del lxd-upgrade - fi - - echo "Bringing down and renaming existing bridge ${LXD_BRIDGE} to lxd-upgrade" - ip link set "${LXD_BRIDGE}" down - ip link set "${LXD_BRIDGE}" name lxd-upgrade -fi - -# Define the bridge in LXD -echo "Creating a new LXD bridge" -if ! lxc network show "${LXD_BRIDGE}" >/dev/null 2>&1; then - lxc network create "${LXD_BRIDGE}" ipv4.address=none ipv6.address=none dns.mode=dynamic --force-local -fi - -# Move the old bridge into place -if [ "${EXISTING}" = "true" ]; then - echo "Moving the old bridge into place" - [ -e "/sys/class/net/${LXD_BRIDGE}" ] && ip link del "${LXD_BRIDGE}" - ip link set lxd-upgrade name "${LXD_BRIDGE}" up -fi - -# Configure the bridge -echo "Configuring the new LXD bridge" -if [ -n "${LXD_CONFILE}" ] && [ -e "${LXD_CONFILE}" ]; then - echo "Setting dnsmasq conf-file to ${LXD_CONFILE}" - lxc network set "${LXD_BRIDGE}" raw.dnsmasq "conf-file=${LXD_CONFILE}" --force-local -fi - -if [ "${LXD_DOMAIN}" != "lxd" ]; then - echo "Setting DNS domain to ${LXD_DOMAIN}" - lxc network set "${LXD_BRIDGE}" dns.domain "${LXD_DOMAIN}" --force-local -fi - -if [ -n "${LXD_IPV4_ADDR}" ] && [ -n "${LXD_IPV4_NETMASK}" ]; then - IPV4_CIDR="${LXD_IPV4_ADDR}/$(maskcidr "${LXD_IPV4_NETMASK}")" - echo "Setting IPv4 network to ${IPV4_CIDR}" - lxc network set "${LXD_BRIDGE}" ipv4.address "${IPV4_CIDR}" --force-local - - if [ -n "${LXD_IPV4_DHCP_RANGE}" ]; then - IPV4_RANGE=$(echo "${LXD_IPV4_DHCP_RANGE}" | sed "s/,/-/") - echo "Setting IPv4 DHCP range to ${IPV4_RANGE}" - lxc network set "${LXD_BRIDGE}" ipv4.dhcp.ranges "${IPV4_RANGE}" --force-local - fi - - if [ "${LXD_IPV4_NAT}" = "true" ]; then - echo "Enabling IPv4 NAT" - lxc network set "${LXD_BRIDGE}" ipv4.nat true --force-local - fi -fi - -if [ -e /proc/sys/net/ipv6 ] && [ -n "${LXD_IPV6_ADDR}" ] && [ -n "${LXD_IPV6_MASK}" ]; then - IPV6_CIDR="${LXD_IPV6_ADDR}/${LXD_IPV6_MASK}" - echo "Setting IPv6 network to ${IPV6_CIDR}" - lxc network set "${LXD_BRIDGE}" ipv6.address "${IPV6_CIDR}" --force-local - - if [ "${LXD_IPV6_NAT}" = "true" ]; then - echo "Enabling IPv6 NAT" - lxc network set "${LXD_BRIDGE}" ipv6.nat true --force-local - fi -fi - -echo "Done converting your bridge, renaming old configuration" -mv /etc/default/lxd-bridge /etc/default/lxd-bridge.upgraded - -echo "Cleaning up lxd-bridge state files" -rm -Rf /var/lib/lxd-bridge /run/lxd-bridge "${LXD_CONF}" From 227588f0931a3452a0839393f7cbf8d54b48c84c Mon Sep 17 00:00:00 2001 From: Simon Deziel Date: Fri, 22 Sep 2023 21:15:27 -0400 Subject: [PATCH 5/5] snapcraft/command/lxc: ~/snap/lxd/current was last used in 2.0 Signed-off-by: Simon Deziel --- snapcraft/commands/lxc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/snapcraft/commands/lxc b/snapcraft/commands/lxc index c520c8bdd..e01ccda93 100755 --- a/snapcraft/commands/lxc +++ b/snapcraft/commands/lxc @@ -28,10 +28,7 @@ fi # Migrate data if needed if [ ! -d "${SNAP_USER_COMMON}/config" ]; then - if [ -d "${SNAP_USER_DATA}/.config/lxc" ]; then - mv "${SNAP_USER_DATA}/.config/lxc" "${SNAP_USER_COMMON}/config" || true - rmdir "${SNAP_USER_DATA}/.config/" || true - elif [ -d "${SNAP_REAL_HOME}/.config/lxc" ]; then + if [ -d "${SNAP_REAL_HOME}/.config/lxc" ]; then cp -r "${SNAP_REAL_HOME}/.config/lxc" "${SNAP_USER_COMMON}/config" || true fi