2015-07-28 12:16:11 +00:00
|
|
|
<?xml version='1.0'?> <!--*-nxml-*-->
|
2019-03-14 13:40:58 +00:00
|
|
|
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
2023-12-25 14:48:33 +00:00
|
|
|
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
|
2020-11-09 04:23:58 +00:00
|
|
|
<!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
|
2015-07-28 12:16:11 +00:00
|
|
|
|
|
|
|
<refentry id="systemd.offline-updates">
|
|
|
|
<refentryinfo>
|
|
|
|
<title>systemd.offline-updates</title>
|
|
|
|
<productname>systemd</productname>
|
|
|
|
</refentryinfo>
|
|
|
|
|
|
|
|
<refmeta>
|
|
|
|
<refentrytitle>systemd.offline-updates</refentrytitle>
|
|
|
|
<manvolnum>7</manvolnum>
|
|
|
|
</refmeta>
|
|
|
|
|
|
|
|
<refnamediv>
|
|
|
|
<refname>systemd.offline-updates</refname>
|
|
|
|
<refpurpose>Implementation of offline updates in systemd</refpurpose>
|
|
|
|
</refnamediv>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Implementing Offline System Updates</title>
|
|
|
|
|
2016-03-16 01:59:11 +00:00
|
|
|
<para>This man page describes how to implement "offline" system updates with systemd. By "offline"
|
2015-07-28 12:16:11 +00:00
|
|
|
OS updates we mean package installations and updates that are run with the system booted into a
|
|
|
|
special system update mode, in order to avoid problems related to conflicts of libraries and
|
|
|
|
services that are currently running with those on disk. This document is inspired by this
|
|
|
|
<ulink url="https://wiki.gnome.org/Design/OS/SoftwareUpdates">GNOME design whiteboard</ulink>.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>The logic:</para>
|
|
|
|
|
|
|
|
<orderedlist>
|
|
|
|
<listitem>
|
2020-07-06 08:49:59 +00:00
|
|
|
<para>The package manager prepares system updates by downloading all (.rpm or .deb or
|
2015-07-28 12:16:11 +00:00
|
|
|
whatever) packages to update off-line in a special directory
|
2019-11-21 19:22:12 +00:00
|
|
|
<filename index="false">/var/lib/system-update</filename> (or
|
2015-07-28 12:16:11 +00:00
|
|
|
another directory of the package/upgrade manager's choice).</para>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
2023-04-17 21:09:24 +00:00
|
|
|
<para>When the user OK'ed the update, the symlink <filename>/system-update</filename> or
|
|
|
|
<filename>/etc/system-update</filename> is created that points to
|
|
|
|
<filename index="false">/var/lib/system-update</filename> (or wherever the directory with
|
|
|
|
the upgrade files is located) and the system is rebooted. This symlink is in the root
|
|
|
|
directory, since we need to check for it very early at boot, at a time where
|
|
|
|
<filename>/var/</filename> is not available yet.</para>
|
2015-07-28 12:16:11 +00:00
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
2016-03-16 01:59:11 +00:00
|
|
|
<para>Very early in the new boot
|
2016-08-06 20:38:09 +00:00
|
|
|
<citerefentry><refentrytitle>systemd-system-update-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>
|
2023-04-17 21:09:24 +00:00
|
|
|
checks whether <filename>/system-update</filename> or
|
|
|
|
<filename>/etc/system-update</filename> exists. If so, it (temporarily and for this boot
|
|
|
|
only) redirects (i.e. symlinks) <filename>default.target</filename> to
|
2018-01-20 02:22:57 +00:00
|
|
|
<filename>system-update.target</filename>, a special target that pulls in the base system
|
2016-03-16 01:59:11 +00:00
|
|
|
(i.e. <filename>sysinit.target</filename>, so that all file systems are mounted but little
|
|
|
|
else) and the system update units.</para>
|
2015-07-28 12:16:11 +00:00
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
2016-11-29 06:19:24 +00:00
|
|
|
<para>The system now continues to boot into <filename>default.target</filename>, and
|
|
|
|
thus into <filename>system-update.target</filename>. This target pulls in all system
|
|
|
|
update units. Only one service should perform an update (see the next point), and all
|
|
|
|
the other ones should exit cleanly with a "success" return code and without doing
|
|
|
|
anything. Update services should be ordered after <filename>sysinit.target</filename>
|
2017-01-19 15:54:22 +00:00
|
|
|
so that the update starts after all file systems have been mounted.</para>
|
2016-03-16 01:59:11 +00:00
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
2016-11-29 06:19:24 +00:00
|
|
|
<para>As the first step, an update service should check if the
|
2023-04-17 21:09:24 +00:00
|
|
|
<filename>/system-update</filename> or <filename>/etc/system-update</filename> symlink
|
|
|
|
points to the location used by that update service. In case it does not exist or points to a
|
|
|
|
different location, the service must exit without error. It is possible for multiple update
|
|
|
|
services to be installed, and for multiple update services to be launched in parallel, and
|
|
|
|
only the one that corresponds to the tool that <emphasis>created</emphasis> the symlink
|
|
|
|
before reboot should perform any actions. It is unsafe to run multiple updates in
|
|
|
|
parallel.</para>
|
2015-07-28 12:16:11 +00:00
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
2016-11-29 06:19:24 +00:00
|
|
|
<para>The update service should now do its job. If applicable and possible, it should
|
|
|
|
create a file system snapshot, then install all packages. After completion (regardless
|
|
|
|
whether the update succeeded or failed) the machine must be rebooted, for example by
|
|
|
|
calling <command>systemctl reboot</command>. In addition, on failure the script should
|
|
|
|
revert to the old file system snapshot (without the symlink).</para>
|
2015-07-28 12:16:11 +00:00
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
2020-07-06 08:49:59 +00:00
|
|
|
<para>The update scripts should exit only after the update is finished. It is expected
|
|
|
|
that the service which performs the update will cause the machine to reboot after it
|
units: add system-update-cleanup.service to guard against offline-update loops
Note: the name is "system-update-cleanup.service" rather than
"system-update-done.service", because it should not run normally, and also
because there's already "systemd-update-done.service", and having them named
so similarly would be confusing.
In https://bugzilla.redhat.com/show_bug.cgi?id=1395686 the system repeatedly
entered system-update.target on boot. Because of a packaging issue, the tool
that created the /system-update symlink could be installed without the service
unit that was supposed to perform the upgrade (and remove the symlink). In
fact, if there are no units in system-update.target, and /system-update symlink
is created, systemd always "hangs" in system-update.target. This is confusing
for users, because there's no feedback what is happening, and fixing this
requires starting an emergency shell somehow, and also knowing that the symlink
must be removed. We should be more resilient in this case, and remove the
symlink automatically ourselves, if there are no upgrade service to handle it.
This adds a service which is started after system-update.target is reached and
the symlink still exists. It nukes the symlink and reboots the machine. It
should subsequently boot into the default default.target.
This is a more general fix for
https://bugzilla.redhat.com/show_bug.cgi?id=1395686 (the packaging issue was
already fixed).
2016-11-29 06:29:02 +00:00
|
|
|
is done. If the <filename>system-update.target</filename> is successfully reached, i.e.
|
2023-04-17 21:09:24 +00:00
|
|
|
all update services have run, and the <filename>/system-update</filename> or
|
|
|
|
<filename>/etc/system-update</filename> symlink still exists, it will be removed and
|
|
|
|
the machine rebooted as a safety measure.</para>
|
2016-11-29 06:19:24 +00:00
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
2023-04-17 21:09:24 +00:00
|
|
|
<para>After a reboot, now that the <filename>/system-update</filename> and
|
|
|
|
<filename>/etc/system-update</filename> symlink is gone, the generator won't redirect
|
|
|
|
<filename>default.target</filename> anymore and the system now boots into the default
|
|
|
|
target again.</para>
|
2015-07-28 12:16:11 +00:00
|
|
|
</listitem>
|
|
|
|
</orderedlist>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Recommendations</title>
|
|
|
|
|
|
|
|
<orderedlist>
|
|
|
|
<listitem>
|
|
|
|
<para>To make things a bit more robust we recommend hooking the update script into
|
2019-11-21 19:22:12 +00:00
|
|
|
<filename>system-update.target</filename> via a <filename index="false">.wants/</filename>
|
2015-07-28 12:16:11 +00:00
|
|
|
symlink in the distribution package, rather than depending on <command>systemctl
|
|
|
|
enable</command> in the postinst scriptlets of your package. More specifically, for your
|
|
|
|
update script create a .service file, without [Install] section, and then add a symlink like
|
2020-03-05 17:38:31 +00:00
|
|
|
<filename index="false">/usr/lib/systemd/system/system-update.target.wants/foobar.service</filename>
|
2019-11-21 19:22:12 +00:00
|
|
|
→ <filename index="false">../foobar.service</filename> to your package.</para>
|
2015-07-28 12:16:11 +00:00
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
2023-04-17 21:09:24 +00:00
|
|
|
<para>Make sure to remove the <filename>/system-update</filename> and
|
|
|
|
<filename>/etc/system-update</filename> symlinks as early as possible in the update
|
|
|
|
script to avoid reboot loops in case the update fails.</para>
|
2015-07-28 12:16:11 +00:00
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
2016-03-16 01:59:11 +00:00
|
|
|
<para>Use <varname>FailureAction=reboot</varname> in the service file for your update script
|
|
|
|
to ensure that a reboot is automatically triggered if the update fails.
|
|
|
|
<varname>FailureAction=</varname> makes sure that the specified unit is activated if your
|
|
|
|
script exits uncleanly (by non-zero error code, or signal/coredump). If your script succeeds
|
|
|
|
you should trigger the reboot in your own code, for example by invoking logind's
|
2016-10-31 12:08:08 +00:00
|
|
|
<command>Reboot()</command> call or calling <command>systemctl reboot</command>. See
|
2020-09-29 06:03:10 +00:00
|
|
|
<citerefentry><refentrytitle>org.freedesktop.login1</refentrytitle><manvolnum>5</manvolnum></citerefentry>
|
|
|
|
for details about the logind D-Bus API.</para>
|
2015-07-28 12:16:11 +00:00
|
|
|
</listitem>
|
2016-03-16 01:59:11 +00:00
|
|
|
|
|
|
|
<listitem>
|
2018-09-25 10:40:35 +00:00
|
|
|
<para>The update service should declare <varname>DefaultDependencies=no</varname>,
|
2016-11-29 06:19:24 +00:00
|
|
|
<varname>Requires=sysinit.target</varname>, <varname>After=sysinit.target</varname>,
|
2019-07-12 16:22:30 +00:00
|
|
|
<varname>After=system-update-pre.target</varname>, <varname>Before=system-update.target</varname>
|
2016-11-29 06:19:24 +00:00
|
|
|
and explicitly pull in any other services it requires.</para>
|
2016-03-16 01:59:11 +00:00
|
|
|
</listitem>
|
2018-06-19 12:33:59 +00:00
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>It may be desirable to always run an auxiliary unit when booting
|
|
|
|
into offline-updates mode, which itself does not install updates. To
|
|
|
|
do this create a .service file with
|
|
|
|
<varname>Wants=system-update-pre.target</varname> and
|
|
|
|
<varname>Before=system-update-pre.target</varname> and add a symlink
|
|
|
|
to that file under
|
2019-11-21 19:22:12 +00:00
|
|
|
<filename index="false">/usr/lib/systemd/system-update.target.wants</filename>
|
2018-06-19 12:33:59 +00:00
|
|
|
.</para>
|
|
|
|
</listitem>
|
2015-07-28 12:16:11 +00:00
|
|
|
</orderedlist>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
2023-12-22 20:04:12 +00:00
|
|
|
<title>See Also</title>
|
2015-07-28 12:16:11 +00:00
|
|
|
|
2023-12-22 18:09:32 +00:00
|
|
|
<para><simplelist type="inline">
|
|
|
|
<member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
|
|
|
|
<member><citerefentry><refentrytitle>systemd.generator</refentrytitle><manvolnum>7</manvolnum></citerefentry></member>
|
|
|
|
<member><citerefentry><refentrytitle>systemd-system-update-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry></member>
|
|
|
|
<member><citerefentry project='mankier'><refentrytitle>dnf.plugin.system-upgrade</refentrytitle><manvolnum>8</manvolnum></citerefentry></member>
|
|
|
|
</simplelist></para>
|
2015-07-28 12:16:11 +00:00
|
|
|
</refsect1>
|
|
|
|
</refentry>
|