{"id":4085,"date":"2022-12-20T17:39:21","date_gmt":"2022-12-20T20:39:21","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/systemd-offlineupdates-man7\/"},"modified":"2022-12-20T17:39:21","modified_gmt":"2022-12-20T20:39:21","slug":"systemd-offlineupdates-man7","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/systemd-offlineupdates-man7\/","title":{"rendered":"SYSTEMD.OFFLINE&minus;UPDATES (man7)"},"content":{"rendered":"<h1 align=\"center\">SYSTEMD.OFFLINE\u2212UPDATES<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#IMPLEMENTING OFFLINE SYSTEM UPDATES\">IMPLEMENTING OFFLINE SYSTEM UPDATES<\/a><br \/> <a href=\"#RECOMMENDATIONS\">RECOMMENDATIONS<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#NOTES\">NOTES<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">systemd.offline-updates \u2212 Implementation of offline updates in systemd<\/p>\n<h2>IMPLEMENTING OFFLINE SYSTEM UPDATES <a name=\"IMPLEMENTING OFFLINE SYSTEM UPDATES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This man page describes how to implement &#8220;offline&#8221; system updates with systemd. By &#8220;offline&#8221; 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 <b><font color=\"#0000FF\">GNOME design whiteboard<\/font><\/b> <small><font color=\"#000000\">[1]<\/font><\/small> <font color=\"#000000\">.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">The logic:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">1. The package manager prepares system updates by downloading all (.rpm or .deb or whatever) packages to update off\u2212line in a special directory \/var\/lib\/system\u2212update (or another directory of the package\/upgrade manager&#8217;s choice).<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">2. When the user OK&#8217;ed the update, the symlink \/system\u2212update is created that points to \/var\/lib\/system\u2212update (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 \/var is not available yet.<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">3. Very early in the new boot <b>systemd-system-update-generator<\/b>(8) checks whether \/system\u2212update exists. If so, it (temporarily and for this boot only) redirects (i.e. symlinks) default.target to system\u2212update.target, a special target that pulls in the base system (i.e. sysinit.target, so that all file systems are mounted but little else) and the system update units.<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">4. The system now continues to boot into default.target, and thus into system\u2212update.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 &#8220;success&#8221; return code and without doing anything. Update services should be ordered after sysinit.target so that the update starts after all file systems have been mounted.<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">5. As the first step, an update service should check if the \/system\u2212update 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 <i>created<\/i> the symlink before reboot should perform any actions. It is unsafe to run multiple updates in parallel.<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">6. 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 <b>systemctl reboot<\/b>. In addition, on failure the script should revert to the old file system snapshot (without the symlink).<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">7. 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 system\u2212update.target is successfully reached, i.e. all update services have run, and the \/system\u2212update symlink still exists, it will be removed and the machine rebooted as a safety measure.<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">8. After a reboot, now that the \/system\u2212update symlink is gone, the generator won&#8217;t redirect default.target anymore and the system now boots into the default target again.<\/font><\/p>\n<h2>RECOMMENDATIONS <a name=\"RECOMMENDATIONS\"><\/a> <\/h2>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">1. To make things a bit more robust we recommend hooking the update script into system\u2212update.target via a .wants\/ symlink in the distribution package, rather than depending on <b>systemctl enable<\/b> 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 \/usr\/lib\/systemd\/system\u2212update.target.wants\/foobar.service \u00e2 ..\/foobar.service to your package.<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">2. Make sure to remove the \/system\u2212update symlink as early as possible in the update script to avoid reboot loops in case the update fails.<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">3. Use <i>FailureAction=reboot<\/i> in the service file for your update script to ensure that a reboot is automatically triggered if the update fails. <i>FailureAction=<\/i> makes sure that the specified unit is activated if your script exits uncleanly (by non\u2212zero error code, or signal\/coredump). If your script succeeds you should trigger the reboot in your own code, for example by invoking logind&#8217;s <b>Reboot()<\/b> call or calling <b>systemctl reboot<\/b>. See<\/font> <b><font color=\"#0000FF\">logind dbus API<\/font><\/b> <small><font color=\"#000000\">[2]<\/font><\/small> <font color=\"#000000\">for details.<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">4. The update service should declare <i>DefaultDependencies=no<\/i>, <i>Requires=sysinit.target<\/i>, <i>After=sysinit.target<\/i>, <i>After=system\u2212update\u2212pre.target<\/i>, <i>Before=system\u2212update.target<\/i> and explicitly pull in any other services it requires.<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">5. It may be desirable to always run an auxiliary unit when booting into offline\u2212updates mode, which itself does not install updates. To do this create a .service file with <i>Wants=system\u2212update\u2212pre.target<\/i> and <i>Before=system\u2212update\u2212pre.target<\/i> and add a symlink to that file under \/usr\/lib\/systemd\/system\u2212update.target.wants .<\/font><\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\"><b>systemd<\/b>(1), <b>systemd.generator<\/b>(7), <b>systemd-system-update-generator<\/b>(8), <b>dnf.plugin.system-upgrade<\/b>(8)<\/font><\/p>\n<h2>NOTES <a name=\"NOTES\"><\/a> <\/h2>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"12%\"><\/td>\n<td width=\"3%\">\n<p style=\"margin-top: 1em\"><font color=\"#000000\">1.<\/font><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"35%\">\n<p style=\"margin-top: 1em\"><font color=\"#000000\">GNOME design whiteboard<\/font><\/p>\n<\/td>\n<td width=\"48%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%;\"><font color=\"#000000\">https:\/\/wiki.gnome.org\/Design\/OS\/SoftwareUpdates<\/font><\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"12%\"><\/td>\n<td width=\"3%\">\n<p style=\"margin-top: 1em\"><font color=\"#000000\">2.<\/font><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"23%\">\n<p style=\"margin-top: 1em\"><font color=\"#000000\">logind dbus API<\/font><\/p>\n<\/td>\n<td width=\"60%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%;\"><font color=\"#000000\">https:\/\/www.freedesktop.org\/wiki\/Software\/systemd\/logind<\/font><\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  systemd.offline-updates \u2212 Implementation of offline updates in systemd <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[971],"tags":[973,972,978],"class_list":["post-4085","post","type-post","status-publish","format-standard","hentry","category-7-miscelanea","tag-973","tag-man7","tag-systemd"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4085","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=4085"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4085\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=4085"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=4085"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=4085"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}