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