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