From 5e98f2cb988e3506c802c1343677c2b27ae727c6 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Wed, 23 Sep 2020 15:42:44 +0200 Subject: [PATCH 1/6] sys-apps/systemd: Enable remote-fs.target too. Since v242, this unit is not enabled by default. Currently the recommended way of initial enablement of the important units is through `systemctl preset-all` with the preset file from systemd. We don't want to do it, because this action creates symlinks in /etc, so we enable those services ourselves by putting the symlinks in /lib. --- .../coreos-overlay/sys-apps/systemd/systemd-9999.ebuild | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sdk_container/src/third_party/coreos-overlay/sys-apps/systemd/systemd-9999.ebuild b/sdk_container/src/third_party/coreos-overlay/sys-apps/systemd/systemd-9999.ebuild index a93e803536..08cc451ea9 100644 --- a/sdk_container/src/third_party/coreos-overlay/sys-apps/systemd/systemd-9999.ebuild +++ b/sdk_container/src/third_party/coreos-overlay/sys-apps/systemd/systemd-9999.ebuild @@ -426,14 +426,15 @@ multilib_src_install_all() { # Flatcar: Don't enable services in /etc, move to /usr. systemd_enable_service multi-user.target systemd-networkd.service systemd_enable_service multi-user.target systemd-resolved.service + systemd_enable_service multi-user.target remote-fs.target systemd_enable_service sysinit.target systemd-timesyncd.service # Flatcar: Enable getty manually. mkdir --parents "${ED}/usr/lib/systemd/system/getty.target.wants" dosym ../getty@.service "/usr/lib/systemd/system/getty.target.wants/getty@tty1.service" - # Flatcar: Do not enable random services if /etc was detected - # as empty!!! + # Flatcar: Use an empty preset file, because systemctl + # preset-all puts symlinks in /etc, not in /usr. rm "${ED}$(usex split-usr '' /usr)/lib/systemd/system-preset/90-systemd.preset" || die insinto $(usex split-usr '' /usr)/lib/systemd/system-preset doins "${FILESDIR}"/99-default.preset From 8a64463b042983fedc38dcb51552ba232b109e8b Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Fri, 25 Sep 2020 09:40:16 +0200 Subject: [PATCH 2/6] sys-apps/systemd: Try harder at not enabling services through /etc At installation time, we usually want to enable services through /lib. This change will stop making the installation to put symlinks for getty in /etc, since we already do it in /lib. --- .../sys-apps/systemd/systemd-9999.ebuild | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sdk_container/src/third_party/coreos-overlay/sys-apps/systemd/systemd-9999.ebuild b/sdk_container/src/third_party/coreos-overlay/sys-apps/systemd/systemd-9999.ebuild index 08cc451ea9..61b6478241 100644 --- a/sdk_container/src/third_party/coreos-overlay/sys-apps/systemd/systemd-9999.ebuild +++ b/sdk_container/src/third_party/coreos-overlay/sys-apps/systemd/systemd-9999.ebuild @@ -507,7 +507,9 @@ save_enabled_units() { } pkg_preinst() { - save_enabled_units {machines,remote-{cryptsetup,fs}}.target getty@tty1.service + # Flatcar: We enable getty and remote-fs unconditionally, so + # no need to find out whether those are enabled or not here. + save_enabled_units {machines,remote-cryptsetup}.target if ! use split-usr; then local dir @@ -559,11 +561,19 @@ pkg_postinst() { # Flatcar: Reenabling systemd-timesyncd service too. systemd_reenable systemd-networkd.service systemd-resolved.service systemd-timesyncd.service + # Flatcar: TODO: Possibly replace `systemctl enable` with + # `systemd_enable_service`, so it potentially could enable the + # services by making symlinks in /lib, instead of /etc? + # Currently does nothing, because ENABLED_UNITS end up being + # empty, but might not be true in future. if [[ ${ENABLED_UNITS[@]} ]]; then systemctl --root="${ROOT:-/}" enable "${ENABLED_UNITS[@]}" fi - if [[ -z ${REPLACING_VERSIONS} ]]; then + # Flatcar: We enable getty and remote-fs targets ourselves + # above. The code below would modify /etc, which we don't + # want. + if false && [[ -z ${REPLACING_VERSIONS} ]]; then if type systemctl &>/dev/null; then systemctl --root="${ROOT:-/}" enable getty@.service remote-fs.target || FAIL=1 fi From 393a645c389031244ff5dad95d5b8be33621a121 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Fri, 25 Sep 2020 20:35:50 +0200 Subject: [PATCH 3/6] sys-apps/systemd: Enable more services from upstream's preset This more or less mimics systemctl preset-all, but with enabling the services in /usr, not in /etc, as /etc is not autoupdated. --- .../sys-apps/systemd/systemd-9999.ebuild | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/sdk_container/src/third_party/coreos-overlay/sys-apps/systemd/systemd-9999.ebuild b/sdk_container/src/third_party/coreos-overlay/sys-apps/systemd/systemd-9999.ebuild index 61b6478241..0f254163d9 100644 --- a/sdk_container/src/third_party/coreos-overlay/sys-apps/systemd/systemd-9999.ebuild +++ b/sdk_container/src/third_party/coreos-overlay/sys-apps/systemd/systemd-9999.ebuild @@ -423,11 +423,20 @@ multilib_src_install_all() { # Flatcar: Don't set any extra environment variables by default. rm "${ED}/usr/lib/environment.d/99-environment.conf" || die - # Flatcar: Don't enable services in /etc, move to /usr. + # Flatcar: These lines more or less follow the systemd's + # preset file (90-systemd.preset). We do it that way, to avoid + # putting symlink in /etc. Please keep the lines in the same + # order as the "enable" lines appear in the preset file. + systemd_enable_service multi-user.target remote-fs.target + systemd_enable_service multi-user.target remote-cryptsetup.target + systemd_enable_service multi-user.target machines.target + # Flatcar: getty@.service is enabled manually below. + systemd_enable_service sysinit.target systemd-timesyncd.service systemd_enable_service multi-user.target systemd-networkd.service systemd_enable_service multi-user.target systemd-resolved.service - systemd_enable_service multi-user.target remote-fs.target - systemd_enable_service sysinit.target systemd-timesyncd.service + # Flatcar: not enabling reboot.target - it has no WantedBy + # entry. + systemd_enable_service remount-fs.target systemd-pstore.service # Flatcar: Enable getty manually. mkdir --parents "${ED}/usr/lib/systemd/system/getty.target.wants" From a65e2ade5b4fdab7a29ff1a53a55f93bc70ce5ee Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Fri, 25 Sep 2020 20:37:37 +0200 Subject: [PATCH 4/6] sys-apps/systemd: Drop the handling of ENABLED_UNITS We are installing systemd from scratch in the image, so there are no previously enabled units to enable or reenable after installation. Also, this code would enable the services in /etc, which we don't want, because /etc is not autoupdated, so the enabled services could end up still being disabled after the update. --- .../sys-apps/systemd/systemd-9999.ebuild | 46 ++++++------------- 1 file changed, 14 insertions(+), 32 deletions(-) diff --git a/sdk_container/src/third_party/coreos-overlay/sys-apps/systemd/systemd-9999.ebuild b/sdk_container/src/third_party/coreos-overlay/sys-apps/systemd/systemd-9999.ebuild index 0f254163d9..b3404c841c 100644 --- a/sdk_container/src/third_party/coreos-overlay/sys-apps/systemd/systemd-9999.ebuild +++ b/sdk_container/src/third_party/coreos-overlay/sys-apps/systemd/systemd-9999.ebuild @@ -505,20 +505,14 @@ migrate_locale() { fi } -save_enabled_units() { - ENABLED_UNITS=() - type systemctl &>/dev/null || return - for x; do - if systemctl --quiet --root="${ROOT:-/}" is-enabled "${x}"; then - ENABLED_UNITS+=( "${x}" ) - fi - done -} +# Flatcar: save_enabled_units function is dropped, because it's +# unused. When building releases, we assume that there was no systemd +# previously, so there are no units to remember. pkg_preinst() { - # Flatcar: We enable getty and remote-fs unconditionally, so - # no need to find out whether those are enabled or not here. - save_enabled_units {machines,remote-cryptsetup}.target + # Flatcar: When building releases, we assume that there was no + # systemd previously, so there are no units to remember, so + # there is no point in calling save_enabled_units. if ! use split-usr; then local dir @@ -567,28 +561,16 @@ pkg_postinst() { # between OpenRC & systemd migrate_locale - # Flatcar: Reenabling systemd-timesyncd service too. - systemd_reenable systemd-networkd.service systemd-resolved.service systemd-timesyncd.service + # Flatcar: Dropping the reenabling, since there earlier there + # was no systemd (we are building the release from scratch + # here). The function checks if the unit is enabled before + # running reenable, which in our case results in no action at + # all (because no service is enabled). - # Flatcar: TODO: Possibly replace `systemctl enable` with - # `systemd_enable_service`, so it potentially could enable the - # services by making symlinks in /lib, instead of /etc? - # Currently does nothing, because ENABLED_UNITS end up being - # empty, but might not be true in future. - if [[ ${ENABLED_UNITS[@]} ]]; then - systemctl --root="${ROOT:-/}" enable "${ENABLED_UNITS[@]}" - fi + # Flatcar: Dropping handling of ENABLED_UNITS. - # Flatcar: We enable getty and remote-fs targets ourselves - # above. The code below would modify /etc, which we don't - # want. - if false && [[ -z ${REPLACING_VERSIONS} ]]; then - if type systemctl &>/dev/null; then - systemctl --root="${ROOT:-/}" enable getty@.service remote-fs.target || FAIL=1 - fi - elog "To enable a useful set of services, run the following:" - elog " systemctl preset-all --preset-mode=enable-only" - fi + # Flatcar: We enable getty and remote-fs targets in /usr + # ourselves above. if [[ -L ${EROOT}/var/lib/systemd/timesync ]]; then rm "${EROOT}/var/lib/systemd/timesync" From 9512007c744f58882313971dc9cac83089f1bad9 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Fri, 25 Sep 2020 20:39:06 +0200 Subject: [PATCH 5/6] sys-apps/systemd: Make a comment more clear --- .../coreos-overlay/sys-apps/systemd/systemd-9999.ebuild | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk_container/src/third_party/coreos-overlay/sys-apps/systemd/systemd-9999.ebuild b/sdk_container/src/third_party/coreos-overlay/sys-apps/systemd/systemd-9999.ebuild index b3404c841c..4340621987 100644 --- a/sdk_container/src/third_party/coreos-overlay/sys-apps/systemd/systemd-9999.ebuild +++ b/sdk_container/src/third_party/coreos-overlay/sys-apps/systemd/systemd-9999.ebuild @@ -443,7 +443,8 @@ multilib_src_install_all() { dosym ../getty@.service "/usr/lib/systemd/system/getty.target.wants/getty@tty1.service" # Flatcar: Use an empty preset file, because systemctl - # preset-all puts symlinks in /etc, not in /usr. + # preset-all puts symlinks in /etc, not in /usr. We don't use + # /etc, because it is not autoupdated. We do the "preset" above. rm "${ED}$(usex split-usr '' /usr)/lib/systemd/system-preset/90-systemd.preset" || die insinto $(usex split-usr '' /usr)/lib/systemd/system-preset doins "${FILESDIR}"/99-default.preset From 498ad0ba089493736e3d76b0b202c6b9e6ec0c46 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Sat, 26 Sep 2020 14:21:45 +0200 Subject: [PATCH 6/6] sys-apps/systemd: Enable more services These normally would be pulled by systemdctl enable when enabling systemd-networkd.service, because they are used in Also= options. In such case, we need to pull them ourselves, so they can be enabled in /usr, not in /etc. --- .../coreos-overlay/sys-apps/systemd/systemd-9999.ebuild | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sdk_container/src/third_party/coreos-overlay/sys-apps/systemd/systemd-9999.ebuild b/sdk_container/src/third_party/coreos-overlay/sys-apps/systemd/systemd-9999.ebuild index 4340621987..1c85c33a2d 100644 --- a/sdk_container/src/third_party/coreos-overlay/sys-apps/systemd/systemd-9999.ebuild +++ b/sdk_container/src/third_party/coreos-overlay/sys-apps/systemd/systemd-9999.ebuild @@ -433,6 +433,12 @@ multilib_src_install_all() { # Flatcar: getty@.service is enabled manually below. systemd_enable_service sysinit.target systemd-timesyncd.service systemd_enable_service multi-user.target systemd-networkd.service + # For systemd-networkd.service, it has it in Also, which also + # needs to be enabled + systemd_enable_service sockets.target systemd-networkd.socket + # For systemd-networkd.service, it has it in Also, which also + # needs to be enabled + systemd_enable_service network-online.target systemd-networkd-wait-online.service systemd_enable_service multi-user.target systemd-resolved.service # Flatcar: not enabling reboot.target - it has no WantedBy # entry.