[lxc-devel] [lxd-pkg-ubuntu/dpm-focal] Add handling for LXD upgrades on Ubuntu on WSL

sirredbeard on Github lxc-bot at linuxcontainers.org
Fri Apr 17 19:20:00 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 511 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200417/c79d28b4/attachment.bin>
-------------- next part --------------
From 709285465de32a1cc23b4904bf4422e1dfd64f71 Mon Sep 17 00:00:00 2001
From: Hayden <hayden.barnes at canonical.com>
Date: Fri, 17 Apr 2020 15:19:24 -0400
Subject: [PATCH] Add handling for LXD upgrades on Ubuntu on WSL

Improves upgrade handling when LXD is upgraded on WSL under certain circumstances.

Fixes https://bugs.launchpad.net/ubuntuwsl/+bug/1862550

Signed-off-by: Hayden Barnes hayden.barnes at canonical.com
---
 debian/lxd.preinst | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/debian/lxd.preinst b/debian/lxd.preinst
index aede3e04..0ece79a4 100644
--- a/debian/lxd.preinst
+++ b/debian/lxd.preinst
@@ -1,6 +1,32 @@
 #!/bin/sh
 set -e
 
+skip_unusable_snapd() {
+    if [ -e "/run/snapd.socket" ]; then
+        # Snapd is present, run the upgrade
+        return 1
+    fi
+
+    if [ ! -e "/var/lib/lxd/server.crt" ]; then
+        # LXD was never used, safe to skip
+        return 0
+    fi
+
+    for path in containers images networks storage-pools; do
+        if [ ! -e "/var/lib/lxd/${path}" ]; then
+            # Path doesn't exist, continue to next one
+            continue
+        fi
+
+        if [ -n "$(ls -A "/var/lib/lxd/${path}")" ]; then
+            # Detected some data, unsafe to skip automatically
+            return 1
+        fi
+    done
+
+    return 0
+}
+
 case "$1" in
     install|upgrade)
         . /usr/share/debconf/confmodule
@@ -23,6 +49,12 @@ case "$1" in
         COUNT=0
         SKIP=false
         while :; do
+            if skip_unusable_snapd; then
+                echo "===> System doesn't have a working snapd and LXD was never used, skipping"
+                SKIP=true
+                break
+            fi
+
             snap info lxd >/dev/null 2>&1 && break
 
             db_fset lxd/snap-no-connectivity seen false


More information about the lxc-devel mailing list