[lxc-devel] [lxd-pkg-ubuntu/dpm-disco] Allow skipping snap installation in preinst when lxd is not activated yet

rbalint on Github lxc-bot at linuxcontainers.org
Fri Apr 5 15:11:33 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 382 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190405/21725efa/attachment-0001.bin>
-------------- next part --------------
From 9d78d8470264fdadb2e196f1447704b950008ba7 Mon Sep 17 00:00:00 2001
From: Balint Reczey <balint.reczey at canonical.com>
Date: Fri, 5 Apr 2019 13:05:21 +0200
Subject: [PATCH] Allow skipping snap installation in preinst when lxd is not
 activated yet

LP: #1821924
Signed-off-by: Balint Reczey <balint.reczey at canonical.com>
---
 debian/lxd.preinst      | 83 ++++++++++++++++++++++++-----------------
 debian/lxd.templates    | 13 ++++++-
 debian/po/templates.pot | 32 ++++++++++++++--
 lxc                     |  6 +++
 lxd                     |  6 +++
 5 files changed, 101 insertions(+), 39 deletions(-)

diff --git a/debian/lxd.preinst b/debian/lxd.preinst
index ea0ec51b..a6e87b1b 100644
--- a/debian/lxd.preinst
+++ b/debian/lxd.preinst
@@ -16,6 +16,7 @@ case "$1" in
         # Check store connectivity
         echo "==> Checking connectivity with the snap store"
         COUNT=0
+        SKIP=false
         while :; do
             snap info lxd >/dev/null 2>&1 && break
 
@@ -41,6 +42,16 @@ case "$1" in
                 if [ "${RET}" = "Abort" ]; then
                     echo "===> Aborting at user request"
                     exit 1
+                elif [ "${RET}" = "Skip" ]; then
+                    if ! [ -e "/var/lib/lxd/server.crt" ]; then
+                        echo "===> Skipping at user request"
+                        SKIP=true
+                        break
+                    else
+                        db_fset lxd/snap-install-cant-be-skipped seen false
+                        db_input critical lxd/snap-install-cant-be-skipped || true
+                        db_go
+                    fi
                 fi
 
                 if [ "${COUNT}" = "0" ]; then
@@ -51,48 +62,53 @@ case "$1" in
             COUNT=$((COUNT+1))
         done
 
-        # Set the default track
-        db_get lxd/snap-track
-        if [ -z "${RET}" ]; then
-            if [ -e "/etc/os-release" ] && grep -q " LTS " /etc/os-release; then
-                db_set lxd/snap-track "3.0"
+        if ! ${SKIP}; then
+
+            # Set the default track
+            db_get lxd/snap-track
+            if [ -z "${RET}" ]; then
+                if [ -e "/etc/os-release" ] && grep -q " LTS " /etc/os-release; then
+                    db_set lxd/snap-track "3.0"
+                fi
+
+                db_fset lxd/snap-track seen false
             fi
 
-            db_fset lxd/snap-track seen false
-        fi
+            # Prompt about track
+            db_input high lxd/snap-track || true
+            db_go
 
-        # Prompt about track
-        db_input high lxd/snap-track || true
-        db_go
+            # Get the track
+            db_get lxd/snap-track
+            track=${RET}
 
-        # Get the track
-        db_get lxd/snap-track
-        track=${RET}
+            # Workaround for broken systems
+            mkdir -p /lib/modules
 
-        # Workaround for broken systems
-        mkdir -p /lib/modules
+            # Extract the OS release
+            RELEASE="18.10"
+            if [ -e "/etc/os-release" ]; then
+                RELEASE=$(. /etc/os-release && echo "${VERSION_ID}")
+            fi
 
-        # Extract the OS release
-        RELEASE="18.10"
-        if [ -e "/etc/os-release" ]; then
-            RELEASE=$(. /etc/os-release && echo "${VERSION_ID}")
-        fi
+            # Install the snap
+            echo "==> Installing the LXD snap from the ${track} track for ubuntu-${RELEASE}"
+            if [ "${track}" = "latest" ]; then
+                snap install lxd --channel="stable/ubuntu-${RELEASE}"
+            else
+                snap install lxd --channel="${track}/stable/ubuntu-${RELEASE}"
+            fi
 
-        # Install the snap
-        echo "==> Installing the LXD snap from the ${track} track for ubuntu-${RELEASE}"
-        if [ "${track}" = "latest" ]; then
-            snap install lxd --channel="stable/ubuntu-${RELEASE}"
-        else
-            snap install lxd --channel="${track}/stable/ubuntu-${RELEASE}"
-        fi
+            if [ -e "/var/lib/lxd/server.crt" ]; then
+                echo "==> Waiting for LXD to be online (10min timeout)"
+                /snap/bin/lxd waitready --timeout=600
 
-        if [ -e "/var/lib/lxd/server.crt" ]; then
-            echo "==> Waiting for LXD to be online (10min timeout)"
-            /snap/bin/lxd waitready --timeout=600
+                echo "==> Running migration from Deb to Snap"
+                export LXD_PREINST=1
+                /snap/bin/lxd.migrate --yes
+            fi
 
-            echo "==> Running migration from Deb to Snap"
-            export LXD_PREINST=1
-            /snap/bin/lxd.migrate --yes
+            echo "=> Snap installation complete"
         fi
 
         echo "==> Cleaning up leftovers"
@@ -106,7 +122,6 @@ case "$1" in
         rm -rf --one-file-system /var/lib/lxd
         rm -rf --one-file-system /var/log/lxd
 
-        echo "=> Snap installation complete"
     ;;
 
     abort-upgrade|abort-remove|abort-deconfigure)
diff --git a/debian/lxd.templates b/debian/lxd.templates
index d8f530ad..9a013e3d 100644
--- a/debian/lxd.templates
+++ b/debian/lxd.templates
@@ -13,7 +13,7 @@ _Description: Upgrade to the LXD snap
 
 Template: lxd/snap-no-connectivity
 Type: select
-Choices: Retry, Abort
+Choices: Retry, Abort, Skip
 _Description: Unable to reach the snap store
  Your system is unable to reach the snap store, please make sure you're
  connected to the Internet and update any firewall or proxy settings as
@@ -23,6 +23,17 @@ _Description: Unable to reach the snap store
  .
  Aborting will cause the upgrade to fail and will require it to be re-attempted
  once snapd is functional on the system.
+ .
+ Skipping will let the package upgrade to continue, but the lxd commands
+ will not be functional until the lxd snap is installed. Skipping is allowed
+ only when lxd is not activated on the system.
+
+Template: lxd/snap-install-cant-be-skipped
+Type: error
+_Description: Skipping is not allowed when lxd is activated
+ LXD is detected to be active or activated in the past. Please stop LXD and
+ remove local data in /var/lib/lxd/ if you would like to skip installing
+ the lxd snap and migrating the local data.
 
 Template: lxd/snap-track
 Type: select
diff --git a/debian/po/templates.pot b/debian/po/templates.pot
index 2e5ccdef..de77540a 100644
--- a/debian/po/templates.pot
+++ b/debian/po/templates.pot
@@ -9,7 +9,7 @@ msgstr ""
 "Project-Id-Version: lxd\n"
 "Report-Msgid-Bugs-To: lxd at packages.debian.org\n"
 "POT-Creation-Date: 2018-09-13 10:25-0400\n"
-"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"PO-Revision-Date:  2019-04-05 13:08+0200\n"
 "Last-Translator: FULL NAME <EMAIL at ADDRESS>\n"
 "Language-Team: LANGUAGE <LL at li.org>\n"
 "Language: \n"
@@ -78,13 +78,37 @@ msgstr ""
 
 #. Type: select
 #. Description
+#: ../lxd.templates:2001
+msgid ""
+"Skipping will let the package upgrade to continue, but the lxd commands will "
+"not be functional until the lxd snap is installed. Skipping is allowed only "
+"when lxd is not activated on the system."
+msgstr ""
+
+#. Type: error
+#. Description
+#: ../lxd.templates:3001
+msgid "Skipping is not allowed when lxd is activated"
+msgstr ""
+
+#. Type: error
+#. Description
 #: ../lxd.templates:3001
+msgid ""
+"LXD is detected to be active or activated in the past. Please stop LXD and "
+"remove local data in /var/lib/lxd/ if you would like to skip installing the "
+"lxd snap and migrating the local data."
+msgstr ""
+
+#. Type: select
+#. Description
+#: ../lxd.templates:4001
 msgid "LXD snap track"
 msgstr ""
 
 #. Type: select
 #. Description
-#: ../lxd.templates:3001
+#: ../lxd.templates:4001
 msgid ""
 "The LXD project puts out monthly feature releases which while backward "
 "compatible at an API and CLI level, will contain some behavior change and "
@@ -93,7 +117,7 @@ msgstr ""
 
 #. Type: select
 #. Description
-#: ../lxd.templates:3001
+#: ../lxd.templates:4001
 msgid ""
 "In addition to those, every 2 years a LTS release is made which comes with 5 "
 "years of support through frequent bugfix-only releases."
@@ -101,7 +125,7 @@ msgstr ""
 
 #. Type: select
 #. Description
-#: ../lxd.templates:3001
+#: ../lxd.templates:4001
 msgid ""
 "The LXD team recommends you pick \"3.0\" for production environments and use "
 "\"latest\" if you're interested in getting the latest LXD features."
diff --git a/lxc b/lxc
index 96b1888d..35138fdd 100755
--- a/lxc
+++ b/lxc
@@ -1,2 +1,8 @@
 #!/bin/sh
+if ! [ -x /snap/bin/lxc ]; then
+    echo "Command '$0' requires the lxd snap to be installed." >2
+    echo "Please install it with:" >2
+    echo "" >2
+    echo "snap install lxd" >2
+fi
 exec /snap/bin/lxc "$@"
diff --git a/lxd b/lxd
index bf0a587c..745f1bc4 100755
--- a/lxd
+++ b/lxd
@@ -1,2 +1,8 @@
 #!/bin/sh
+if ! [ -x /snap/bin/lxd ]; then
+    echo "Command '$0' requires the lxd snap to be installed." >2
+    echo "Please install it with:" >2
+    echo "" >2
+    echo "snap install lxd" >2
+fi
 exec /snap/bin/lxd "$@"


More information about the lxc-devel mailing list