]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/systemd.offline-updates.xml
Merge pull request #11519 from yuwata/udevadm-info-2476
[thirdparty/systemd.git] / man / systemd.offline-updates.xml
CommitLineData
c5915c63
ZJS
1<?xml version='1.0'?> <!--*-nxml-*-->
2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4
5<!--
572eb058 6 SPDX-License-Identifier: LGPL-2.1+
c5915c63
ZJS
7-->
8
9<refentry id="systemd.offline-updates">
10 <refentryinfo>
11 <title>systemd.offline-updates</title>
12 <productname>systemd</productname>
c5915c63
ZJS
13 </refentryinfo>
14
15 <refmeta>
16 <refentrytitle>systemd.offline-updates</refentrytitle>
17 <manvolnum>7</manvolnum>
18 </refmeta>
19
20 <refnamediv>
21 <refname>systemd.offline-updates</refname>
22 <refpurpose>Implementation of offline updates in systemd</refpurpose>
23 </refnamediv>
24
25 <refsect1>
26 <title>Implementing Offline System Updates</title>
27
45f0c64e 28 <para>This man page describes how to implement "offline" system updates with systemd. By "offline"
c5915c63
ZJS
29 OS updates we mean package installations and updates that are run with the system booted into a
30 special system update mode, in order to avoid problems related to conflicts of libraries and
31 services that are currently running with those on disk. This document is inspired by this
32 <ulink url="https://wiki.gnome.org/Design/OS/SoftwareUpdates">GNOME design whiteboard</ulink>.
33 </para>
34
35 <para>The logic:</para>
36
37 <orderedlist>
38 <listitem>
39 <para>The package manager prepares system updates by downloading all (RPM or DEB or
40 whatever) packages to update off-line in a special directory
41 <filename noindex="true">/var/lib/system-update</filename> (or
42 another directory of the package/upgrade manager's choice).</para>
43 </listitem>
44
45 <listitem>
46 <para>When the user OK'ed the update, the symlink <filename>/system-update</filename> is
45f0c64e
ZJS
47 created that points to <filename noindex="true">/var/lib/system-update</filename> (or
48 wherever the directory with the upgrade files is located) and the system is rebooted. This
c5915c63
ZJS
49 symlink is in the root directory, since we need to check for it very early at boot, at a
50 time where <filename>/var</filename> is not available yet.</para>
51 </listitem>
52
53 <listitem>
45f0c64e 54 <para>Very early in the new boot
2ac5fe95 55 <citerefentry><refentrytitle>systemd-system-update-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>
45f0c64e
ZJS
56 checks whether <filename>/system-update</filename> exists. If so, it (temporarily and for
57 this boot only) redirects (i.e. symlinks) <filename>default.target</filename> to
fec0ccea 58 <filename>system-update.target</filename>, a special target that pulls in the base system
45f0c64e
ZJS
59 (i.e. <filename>sysinit.target</filename>, so that all file systems are mounted but little
60 else) and the system update units.</para>
c5915c63
ZJS
61 </listitem>
62
63 <listitem>
2b656050
ZJS
64 <para>The system now continues to boot into <filename>default.target</filename>, and
65 thus into <filename>system-update.target</filename>. This target pulls in all system
66 update units. Only one service should perform an update (see the next point), and all
67 the other ones should exit cleanly with a "success" return code and without doing
68 anything. Update services should be ordered after <filename>sysinit.target</filename>
301a21a8 69 so that the update starts after all file systems have been mounted.</para>
45f0c64e
ZJS
70 </listitem>
71
72 <listitem>
2b656050 73 <para>As the first step, an update service should check if the
61233823 74 <filename>/system-update</filename> symlink points to the location used by that update
2b656050 75 service. In case it does not exist or points to a different location, the service must exit
45f0c64e 76 without error. It is possible for multiple update services to be installed, and for multiple
2b656050 77 update services to be launched in parallel, and only the one that corresponds to the tool
45f0c64e
ZJS
78 that <emphasis>created</emphasis> the symlink before reboot should perform any actions. It
79 is unsafe to run multiple updates in parallel.</para>
c5915c63
ZJS
80 </listitem>
81
82 <listitem>
2b656050
ZJS
83 <para>The update service should now do its job. If applicable and possible, it should
84 create a file system snapshot, then install all packages. After completion (regardless
85 whether the update succeeded or failed) the machine must be rebooted, for example by
86 calling <command>systemctl reboot</command>. In addition, on failure the script should
87 revert to the old file system snapshot (without the symlink).</para>
c5915c63
ZJS
88 </listitem>
89
90 <listitem>
2b656050
ZJS
91 <para>The upgrade scripts should exit only after the update is finished. It is expected
92 that the service which performs the upgrade will cause the machine to reboot after it
953bf460
ZJS
93 is done. If the <filename>system-update.target</filename> is successfully reached, i.e.
94 all update services have run, and the <filename>/system-update</filename> symlink still
95 exists, it will be removed and the machine rebooted as a safety measure.</para>
2b656050
ZJS
96 </listitem>
97
98 <listitem>
99 <para>After a reboot, now that the <filename>/system-update</filename> symlink is gone,
100 the generator won't redirect <filename>default.target</filename> anymore and the system
101 now boots into the default target again.</para>
c5915c63
ZJS
102 </listitem>
103 </orderedlist>
104 </refsect1>
105
106 <refsect1>
107 <title>Recommendations</title>
108
109 <orderedlist>
110 <listitem>
111 <para>To make things a bit more robust we recommend hooking the update script into
112 <filename>system-update.target</filename> via a <filename noindex='true'>.wants/</filename>
113 symlink in the distribution package, rather than depending on <command>systemctl
114 enable</command> in the postinst scriptlets of your package. More specifically, for your
115 update script create a .service file, without [Install] section, and then add a symlink like
116 <filename noindex='true'>/usr/lib/systemd/system-update.target.wants/foobar.service</filename>
117 → <filename noindex='true'>../foobar.service</filename> to your package.</para>
118 </listitem>
119
120 <listitem>
45f0c64e
ZJS
121 <para>Make sure to remove the <filename>/system-update</filename> symlink as early as
122 possible in the update script to avoid reboot loops in case the update fails.</para>
c5915c63
ZJS
123 </listitem>
124
125 <listitem>
45f0c64e
ZJS
126 <para>Use <varname>FailureAction=reboot</varname> in the service file for your update script
127 to ensure that a reboot is automatically triggered if the update fails.
128 <varname>FailureAction=</varname> makes sure that the specified unit is activated if your
129 script exits uncleanly (by non-zero error code, or signal/coredump). If your script succeeds
130 you should trigger the reboot in your own code, for example by invoking logind's
b17649ee 131 <command>Reboot()</command> call or calling <command>systemctl reboot</command>. See
28a0ad81 132 <ulink url="https://www.freedesktop.org/wiki/Software/systemd/logind">logind dbus API</ulink>
c5915c63
ZJS
133 for details.</para>
134 </listitem>
45f0c64e
ZJS
135
136 <listitem>
964c4eda 137 <para>The update service should declare <varname>DefaultDependencies=no</varname>,
2b656050 138 <varname>Requires=sysinit.target</varname>, <varname>After=sysinit.target</varname>,
520741d0 139 <varname>After=system-update-pre.target</varname>
2b656050 140 and explicitly pull in any other services it requires.</para>
45f0c64e 141 </listitem>
bc3c5e16
HG
142
143 <listitem>
144 <para>It may be desirable to always run an auxiliary unit when booting
145 into offline-updates mode, which itself does not install updates. To
146 do this create a .service file with
147 <varname>Wants=system-update-pre.target</varname> and
148 <varname>Before=system-update-pre.target</varname> and add a symlink
149 to that file under
150 <filename noindex='true'>/usr/lib/systemd/system-update.target.wants</filename>
151 .</para>
152 </listitem>
c5915c63
ZJS
153 </orderedlist>
154 </refsect1>
155
156 <refsect1>
157 <title>See also</title>
158
159 <para>
c5915c63 160 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
45f0c64e 161 <citerefentry><refentrytitle>systemd.generator</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
2ac5fe95 162 <citerefentry><refentrytitle>systemd-system-update-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
0a07667d 163 <citerefentry project='mankier'><refentrytitle>dnf.plugin.system-upgrade</refentrytitle><manvolnum>8</manvolnum></citerefentry>
c5915c63
ZJS
164 </para>
165 </refsect1>
166</refentry>