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