Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

static/run-snapd-from-snap: adapt to new mount place for snapd snap #255

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions static/usr/lib/core/run-snapd-from-snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,40 @@

set -eux

# run_on_unseeded will mount/run snapd on an unseeded system
# run_on_unseeded will run snapd on an unseeded system. The snapd snap
# is expected to have been mounted and current link is expected to
# have been created by the initramfs.
run_on_unseeded() {
SNAPD_BASE_DIR="/run/mnt/snapd"

# We need to initialize /snap/snapd/current symlink so that the
# dynanic linker
# /snap/snapd/current/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
# is available to run snapd.
[ -d /snap/snapd ] || mkdir -p /snap/snapd
ln -sf "${SNAPD_BASE_DIR}" /snap/snapd/current
SNAPD_BASE_DIR="/snap/snapd/current"
if ! mountpoint -q "$SNAPD_BASE_DIR"; then
# Compatibility with old way where we had a duplicated mount in /run
# and "current" link was not created by initramfs.
SNAPD_BASE_DIR="/run/mnt/snapd"
# We need to initialize /snap/snapd/current symlink so that the
# dynamic linker
# /snap/snapd/current/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
# is available to run snapd.
[ -d /snap/snapd ] || mkdir -p /snap/snapd
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think about it, the condition was useless here, right? Maybe you can remove it in the same time.

ln -sf "${SNAPD_BASE_DIR}" /snap/snapd/current
fi

# snapd will write all its needed snapd.{service,socket}
# units and restart once it seeded the snapd snap. We create
# a systemd socket unit so that systemd own the socket, otherwise
# a systemd socket unit so that systemd owns the socket, otherwise
# the socket file would be removed by snapd on exit and the snapd.seeded
# service will fail because it has nothing to talk to anymore.
systemd-run --unit=snapd-seeding --service-type=notify --socket-property ListenStream=/run/snapd.socket --socket-property ListenStream=/run/snapd-snap.socket --property KeyringMode=inherit "$SNAPD_BASE_DIR"/usr/lib/snapd/snapd
systemd-run --unit=snapd-seeding --service-type=notify \
--socket-property ListenStream=/run/snapd.socket \
--socket-property ListenStream=/run/snapd-snap.socket \
--property KeyringMode=inherit "$SNAPD_BASE_DIR"/usr/lib/snapd/snapd
# we need to start the snapd service from above explicitly, systemd-run
# only enables the socket but does not start the service.
systemctl start --wait snapd-seeding.service
# at this point the snapd.socket is available
systemctl stop snapd-seeding.socket

# At this point snap is available and seeding is at the point where
# were snapd to installed and restarted successfully. Show progress
# were snapd is installed and restarted successfully. Show progress
# now. Even without showing progress we *must* wait here until
# seeding is done to ensure that console-conf is only started
# after this script has finished.
Expand All @@ -40,8 +49,8 @@ run_on_unseeded() {
# Unseeded systems need to be seeded first, this will start snapd
# and snapd will restart itself after the seeding.
set +e
# systemctl status returns exit code 4 for missing services, and 3 for disabled
# services
# systemctl status returns exit code 4 for missing services, and 3 for
# non-running services
systemctl status snapd.service
snapdExists=$?
if [ ! -e /var/lib/snapd/state.json ] || [ $snapdExists = 4 ] ; then
Expand All @@ -53,4 +62,3 @@ if [ ! -e /var/lib/snapd/state.json ] || [ $snapdExists = 4 ] ; then
exit 0
fi
set -e

Loading