From f59665881191b7439bdbb5c7795f5ab6f2df1506 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 8 May 2024 11:11:43 +0200 Subject: [PATCH] importd: allow activation in early boot, and make it socket activatable Previously, importd was only accessible via D-Bus, which required it to be a late boot service. Now that we have Varlink we can rearrange things to become early-boot activated, just after the image directories are mounted. This will later allow us to have generator that auto-downloads images on boot. --- src/import/importd.c | 2 +- units/meson.build | 5 +++++ units/systemd-importd.service.in | 8 +++++++- units/systemd-importd.socket | 24 ++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 units/systemd-importd.socket diff --git a/src/import/importd.c b/src/import/importd.c index 5ef89ac8844..112180c8465 100644 --- a/src/import/importd.c +++ b/src/import/importd.c @@ -1743,7 +1743,7 @@ static int manager_connect_bus(Manager *m) { assert(m->event); assert(!m->bus); - r = sd_bus_default_system(&m->bus); + r = bus_open_system_watch_bind(&m->bus); if (r < 0) return log_error_errno(r, "Failed to get system bus connection: %m"); diff --git a/units/meson.build b/units/meson.build index b231341a1fb..bdc34e6f2c8 100644 --- a/units/meson.build +++ b/units/meson.build @@ -361,6 +361,11 @@ units = [ 'conditions' : ['ENABLE_IMPORTD'], 'symlinks' : ['dbus-org.freedesktop.import1.service'], }, + { + 'file' : 'systemd-importd.socket', + 'conditions' : ['ENABLE_IMPORTD'], + 'symlinks' : ['sockets.target.wants/'], + }, { 'file' : 'systemd-initctl.service.in', 'conditions' : ['HAVE_SYSV_COMPAT'], diff --git a/units/systemd-importd.service.in b/units/systemd-importd.service.in index daa93776e17..e119d409292 100644 --- a/units/systemd-importd.service.in +++ b/units/systemd-importd.service.in @@ -8,9 +8,15 @@ # (at your option) any later version. [Unit] -Description=Virtual Machine and Container Download Service +Description=Disk Image Download Service Documentation=man:systemd-importd.service(8) Documentation=man:org.freedesktop.import1(5) +DefaultDependencies=no +After=systemd-importd.socket +WantsMountsFor=/var/lib/machines /var/lib/portables /var/lib/extensions /var/lib/confexts +After=systemd-remount-fs.service +Before=shutdown.target +Conflicts=shutdown.target [Service] Type=notify diff --git a/units/systemd-importd.socket b/units/systemd-importd.socket new file mode 100644 index 00000000000..d1c9c22a4cd --- /dev/null +++ b/units/systemd-importd.socket @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +# +# This file is part of systemd. +# +# systemd is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. + +[Unit] +Description=Disk Image Download Service Socket +Documentation=man:systemd-importd.service(8) +Documentation=man:org.freedesktop.import1(5) +DefaultDependencies=no +WantsMountsFor=/var/lib/machines /var/lib/portables /var/lib/extensions /var/lib/confexts +After=systemd-remount-fs.service +Before=sockets.target +Conflicts=shutdown.target +Before=shutdown.target + +[Socket] +ListenStream=/run/systemd/io.systemd.Import +FileDescriptorName=varlink +SocketMode=0666