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