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