| 1 |
'\" t |
| 2 |
.TH "SYSTEMD\&.OFFLINE\-UPDATES" "7" "" "systemd 261~rc3" "systemd.offline-updates" |
| 3 |
.\" ----------------------------------------------------------------- |
| 4 |
.\" * Define some portability stuff |
| 5 |
.\" ----------------------------------------------------------------- |
| 6 |
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 7 |
.\" http://bugs.debian.org/507673 |
| 8 |
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html |
| 9 |
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 10 |
.ie \n(.g .ds Aq \(aq |
| 11 |
.el .ds Aq ' |
| 12 |
.\" ----------------------------------------------------------------- |
| 13 |
.\" * set default formatting |
| 14 |
.\" ----------------------------------------------------------------- |
| 15 |
.\" disable hyphenation |
| 16 |
.nh |
| 17 |
.\" disable justification (adjust text to left margin only) |
| 18 |
.ad l |
| 19 |
.\" ----------------------------------------------------------------- |
| 20 |
.\" * MAIN CONTENT STARTS HERE * |
| 21 |
.\" ----------------------------------------------------------------- |
| 22 |
.SH "NAME" |
| 23 |
systemd.offline-updates \- Implementation of offline updates in systemd |
| 24 |
.SH "IMPLEMENTING OFFLINE SYSTEM UPDATES" |
| 25 |
.PP |
| 26 |
This man page describes how to implement "offline" system updates with systemd\&. By "offline" OS updates we mean package installations and updates that are run with the system booted into a special system update mode, in order to avoid problems related to conflicts of libraries and services that are currently running with those on disk\&. This document is inspired by this |
| 27 |
\m[blue]\fBGNOME design whiteboard\fR\m[]\&\s-2\u[1]\d\s+2\&. |
| 28 |
.PP |
| 29 |
The logic: |
| 30 |
.sp |
| 31 |
.RS 4 |
| 32 |
.ie n \{\ |
| 33 |
\h'-04' 1.\h'+01'\c |
| 34 |
.\} |
| 35 |
.el \{\ |
| 36 |
.sp -1 |
| 37 |
.IP " 1." 4.2 |
| 38 |
.\} |
| 39 |
The package manager prepares system updates by downloading all (\&.rpm or \&.deb or whatever) packages to update off\-line in a special directory |
| 40 |
/var/lib/system\-update |
| 41 |
(or another directory of the package/upgrade manager\*(Aqs choice)\&. |
| 42 |
.RE |
| 43 |
.sp |
| 44 |
.RS 4 |
| 45 |
.ie n \{\ |
| 46 |
\h'-04' 2.\h'+01'\c |
| 47 |
.\} |
| 48 |
.el \{\ |
| 49 |
.sp -1 |
| 50 |
.IP " 2." 4.2 |
| 51 |
.\} |
| 52 |
When the user OK\*(Aqed the update, the symlink |
| 53 |
/system\-update |
| 54 |
or |
| 55 |
/etc/system\-update |
| 56 |
is created that points to |
| 57 |
/var/lib/system\-update |
| 58 |
(or wherever the directory with the upgrade files is located) and the system is rebooted\&. This symlink is in the root directory, since we need to check for it very early at boot, at a time where |
| 59 |
/var/ |
| 60 |
is not available yet\&. |
| 61 |
.RE |
| 62 |
.sp |
| 63 |
.RS 4 |
| 64 |
.ie n \{\ |
| 65 |
\h'-04' 3.\h'+01'\c |
| 66 |
.\} |
| 67 |
.el \{\ |
| 68 |
.sp -1 |
| 69 |
.IP " 3." 4.2 |
| 70 |
.\} |
| 71 |
Very early in the new boot |
| 72 |
\fBsystemd-system-update-generator\fR(8) |
| 73 |
checks whether |
| 74 |
/system\-update |
| 75 |
or |
| 76 |
/etc/system\-update |
| 77 |
exists\&. If so, it (temporarily and for this boot only) redirects (i\&.e\&. symlinks) |
| 78 |
default\&.target |
| 79 |
to |
| 80 |
system\-update\&.target, a special target that pulls in the base system (i\&.e\&. |
| 81 |
sysinit\&.target, so that all file systems are mounted but little else) and the system update units\&. |
| 82 |
.RE |
| 83 |
.sp |
| 84 |
.RS 4 |
| 85 |
.ie n \{\ |
| 86 |
\h'-04' 4.\h'+01'\c |
| 87 |
.\} |
| 88 |
.el \{\ |
| 89 |
.sp -1 |
| 90 |
.IP " 4." 4.2 |
| 91 |
.\} |
| 92 |
The system now continues to boot into |
| 93 |
default\&.target, and thus into |
| 94 |
system\-update\&.target\&. This target pulls in all system update units\&. Only one service should perform an update (see the next point), and all the other ones should exit cleanly with a "success" return code and without doing anything\&. Update services should be ordered after |
| 95 |
sysinit\&.target |
| 96 |
so that the update starts after all file systems have been mounted\&. |
| 97 |
.RE |
| 98 |
.sp |
| 99 |
.RS 4 |
| 100 |
.ie n \{\ |
| 101 |
\h'-04' 5.\h'+01'\c |
| 102 |
.\} |
| 103 |
.el \{\ |
| 104 |
.sp -1 |
| 105 |
.IP " 5." 4.2 |
| 106 |
.\} |
| 107 |
As the first step, an update service should check if the |
| 108 |
/system\-update |
| 109 |
or |
| 110 |
/etc/system\-update |
| 111 |
symlink points to the location used by that update service\&. In case it does not exist or points to a different location, the service must exit without error\&. It is possible for multiple update services to be installed, and for multiple update services to be launched in parallel, and only the one that corresponds to the tool that |
| 112 |
\fIcreated\fR |
| 113 |
the symlink before reboot should perform any actions\&. It is unsafe to run multiple updates in parallel\&. |
| 114 |
.RE |
| 115 |
.sp |
| 116 |
.RS 4 |
| 117 |
.ie n \{\ |
| 118 |
\h'-04' 6.\h'+01'\c |
| 119 |
.\} |
| 120 |
.el \{\ |
| 121 |
.sp -1 |
| 122 |
.IP " 6." 4.2 |
| 123 |
.\} |
| 124 |
The update service should now do its job\&. If applicable and possible, it should create a file system snapshot, then install all packages\&. After completion (regardless whether the update succeeded or failed) the machine must be rebooted, for example by calling |
| 125 |
\fBsystemctl reboot\fR\&. In addition, on failure the script should revert to the old file system snapshot (without the symlink)\&. |
| 126 |
.RE |
| 127 |
.sp |
| 128 |
.RS 4 |
| 129 |
.ie n \{\ |
| 130 |
\h'-04' 7.\h'+01'\c |
| 131 |
.\} |
| 132 |
.el \{\ |
| 133 |
.sp -1 |
| 134 |
.IP " 7." 4.2 |
| 135 |
.\} |
| 136 |
The update scripts should exit only after the update is finished\&. It is expected that the service which performs the update will cause the machine to reboot after it is done\&. If the |
| 137 |
system\-update\&.target |
| 138 |
is successfully reached, i\&.e\&. all update services have run, and the |
| 139 |
/system\-update |
| 140 |
or |
| 141 |
/etc/system\-update |
| 142 |
symlink still exists, it will be removed and the machine rebooted as a safety measure\&. |
| 143 |
.RE |
| 144 |
.sp |
| 145 |
.RS 4 |
| 146 |
.ie n \{\ |
| 147 |
\h'-04' 8.\h'+01'\c |
| 148 |
.\} |
| 149 |
.el \{\ |
| 150 |
.sp -1 |
| 151 |
.IP " 8." 4.2 |
| 152 |
.\} |
| 153 |
After a reboot, now that the |
| 154 |
/system\-update |
| 155 |
and |
| 156 |
/etc/system\-update |
| 157 |
symlink is gone, the generator will not redirect |
| 158 |
default\&.target |
| 159 |
anymore and the system now boots into the default target again\&. |
| 160 |
.RE |
| 161 |
.SH "RECOMMENDATIONS" |
| 162 |
.sp |
| 163 |
.RS 4 |
| 164 |
.ie n \{\ |
| 165 |
\h'-04' 1.\h'+01'\c |
| 166 |
.\} |
| 167 |
.el \{\ |
| 168 |
.sp -1 |
| 169 |
.IP " 1." 4.2 |
| 170 |
.\} |
| 171 |
To make things a bit more robust we recommend hooking the update script into |
| 172 |
system\-update\&.target |
| 173 |
via a |
| 174 |
\&.wants/ |
| 175 |
symlink in the distribution package, rather than depending on |
| 176 |
\fBsystemctl enable\fR |
| 177 |
in the postinst scriptlets of your package\&. More specifically, for your update script create a \&.service file, without [Install] section, and then add a symlink like |
| 178 |
/usr/lib/systemd/system/system\-update\&.target\&.wants/foobar\&.service |
| 179 |
→ |
| 180 |
\&.\&./foobar\&.service |
| 181 |
to your package\&. |
| 182 |
.RE |
| 183 |
.sp |
| 184 |
.RS 4 |
| 185 |
.ie n \{\ |
| 186 |
\h'-04' 2.\h'+01'\c |
| 187 |
.\} |
| 188 |
.el \{\ |
| 189 |
.sp -1 |
| 190 |
.IP " 2." 4.2 |
| 191 |
.\} |
| 192 |
Make sure to remove the |
| 193 |
/system\-update |
| 194 |
and |
| 195 |
/etc/system\-update |
| 196 |
symlinks as early as possible in the update script to avoid reboot loops in case the update fails\&. |
| 197 |
.RE |
| 198 |
.sp |
| 199 |
.RS 4 |
| 200 |
.ie n \{\ |
| 201 |
\h'-04' 3.\h'+01'\c |
| 202 |
.\} |
| 203 |
.el \{\ |
| 204 |
.sp -1 |
| 205 |
.IP " 3." 4.2 |
| 206 |
.\} |
| 207 |
Use |
| 208 |
\fIFailureAction=reboot\fR |
| 209 |
in the service file for your update script to ensure that a reboot is automatically triggered if the update fails\&. |
| 210 |
\fIFailureAction=\fR |
| 211 |
makes sure that the specified unit is activated if your script exits uncleanly (by non\-zero error code, or signal/coredump)\&. If your script succeeds you should trigger the reboot in your own code, for example by invoking logind\*(Aqs |
| 212 |
\fBReboot()\fR |
| 213 |
call or calling |
| 214 |
\fBsystemctl reboot\fR\&. See |
| 215 |
\fBorg.freedesktop.login1\fR(5) |
| 216 |
for details about the logind D\-Bus API\&. |
| 217 |
.RE |
| 218 |
.sp |
| 219 |
.RS 4 |
| 220 |
.ie n \{\ |
| 221 |
\h'-04' 4.\h'+01'\c |
| 222 |
.\} |
| 223 |
.el \{\ |
| 224 |
.sp -1 |
| 225 |
.IP " 4." 4.2 |
| 226 |
.\} |
| 227 |
The update service should declare |
| 228 |
\fIDefaultDependencies=no\fR, |
| 229 |
\fIRequires=sysinit\&.target\fR, |
| 230 |
\fIAfter=sysinit\&.target\fR, |
| 231 |
\fIAfter=system\-update\-pre\&.target\fR, |
| 232 |
\fIBefore=system\-update\&.target\fR |
| 233 |
and explicitly pull in any other services it requires\&. |
| 234 |
.RE |
| 235 |
.sp |
| 236 |
.RS 4 |
| 237 |
.ie n \{\ |
| 238 |
\h'-04' 5.\h'+01'\c |
| 239 |
.\} |
| 240 |
.el \{\ |
| 241 |
.sp -1 |
| 242 |
.IP " 5." 4.2 |
| 243 |
.\} |
| 244 |
It may be desirable to always run an auxiliary unit when booting into offline\-updates mode, which itself does not install updates\&. To do this create a \&.service file with |
| 245 |
\fIWants=system\-update\-pre\&.target\fR |
| 246 |
and |
| 247 |
\fIBefore=system\-update\-pre\&.target\fR |
| 248 |
and add a symlink to that file under |
| 249 |
/usr/lib/systemd/system\-update\&.target\&.wants |
| 250 |
\&. |
| 251 |
.RE |
| 252 |
.SH "SEE ALSO" |
| 253 |
.PP |
| 254 |
\fBsystemd\fR(1), \fBsystemd.generator\fR(7), \fBsystemd-system-update-generator\fR(8), \fBdnf.plugin.system-upgrade\fR(8) |
| 255 |
.SH "NOTES" |
| 256 |
.IP " 1." 4 |
| 257 |
GNOME design whiteboard |
| 258 |
.RS 4 |
| 259 |
\%https://wiki.gnome.org/Design/OS/SoftwareUpdates |
| 260 |
.RE |