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