Skip to content

Commit

Permalink
manager: optionally, do a full preset on first boot
Browse files Browse the repository at this point in the history
A compile time option is added to select behaviour: by default
UNIT_FILE_PRESET_ENABLE_ONLY is still used, but the intent is to change to
UNIT_FILE_PRESET_FULL at some point in the future. Distros that want to
opt-in can use the config option to change the behaviour.

(The option is just a boolean: it would be possible to make it multi-valued,
and allow full, enable-only, disable-only, none. But so far nobody has asked
for this, and it's better not to complicate things needlessly.)

With the configuration option flipped, instead of only doing enablements,
perform a full preset on first boot. The reason is that although
`/etc/machine-id` might be missing, there may be other files provisioned in
`/etc` (in fact, this use case is mentioned in `log_execution_mode`). Some of
those possible files include enablement symlinks even if presets dictate it
should be disabled.

Such a seemingly contradictory situation occurs in {RHEL,Fedora} CoreOS,
where we ship `/etc` as if `preset-all` were called. However, we want to
allow users to disable default-enabled services via Ignition, which does
this by creating preset dropins before switchroot. (For why we do
`preset-all` at compose time, see:
coreos/fedora-coreos-config#77).

For example, the composed FCOS image has a `enable zincati.service`
preset and an enablement for that in `/etc`, while at boot time when we
switch root, there may be a `disable zincati.service` preset with higher
precedence. In that case, we want systemd to disable the service.

This is essentially a revert of 304b307. It seems like systemd
*used* to do this, but it was changed to try to make the container
workflow a bit faster.

Resolves: coreos/fedora-coreos-tracker#392

Co-authored-by: Zbigniew Jędrzejewski-Szmek <[email protected]>
  • Loading branch information
jlebon and keszybz committed May 4, 2022
1 parent c1e0dc9 commit 9365158
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ conf.set10('MEMORY_ACCOUNTING_DEFAULT', memory_accounting_
conf.set('STATUS_UNIT_FORMAT_DEFAULT', 'STATUS_UNIT_FORMAT_' + status_unit_format_default.to_upper())
conf.set_quoted('STATUS_UNIT_FORMAT_DEFAULT_STR', status_unit_format_default)

conf.set10('FIRST_BOOT_FULL_PRESET', get_option('first-boot-full-preset'))

#####################################################################

cc = meson.get_compiler('c')
Expand Down Expand Up @@ -4271,6 +4273,7 @@ foreach tuple : [
['link-networkd-shared', get_option('link-networkd-shared')],
['link-timesyncd-shared', get_option('link-timesyncd-shared')],
['link-boot-shared', get_option('link-boot-shared')],
['first-boot-full-preset'],
['fexecve'],
['standalone-binaries', get_option('standalone-binaries')],
['coverage', get_option('b_coverage')],
Expand Down
2 changes: 2 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ option('link-timesyncd-shared', type: 'boolean',
description : 'link systemd-timesyncd and its helpers to libsystemd-shared.so')
option('link-boot-shared', type: 'boolean',
description : 'link bootctl and systemd-bless-boot against libsystemd-shared.so')
option('first-boot-full-preset', type: 'boolean', value: false,
description : 'during first boot, do full preset-all (default will be changed to true later)')

option('static-libsystemd', type : 'combo',
choices : ['false', 'true', 'pic', 'no-pic'],
Expand Down
4 changes: 3 additions & 1 deletion src/core/manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -1728,7 +1728,9 @@ static void manager_preset_all(Manager *m) {
return;

/* If this is the first boot, and we are in the host system, then preset everything */
r = unit_file_preset_all(LOOKUP_SCOPE_SYSTEM, 0, NULL, UNIT_FILE_PRESET_ENABLE_ONLY, NULL, 0);
UnitFilePresetMode mode = FIRST_BOOT_FULL_PRESET ? UNIT_FILE_PRESET_FULL : UNIT_FILE_PRESET_ENABLE_ONLY;

r = unit_file_preset_all(LOOKUP_SCOPE_SYSTEM, 0, NULL, mode, NULL, 0);
if (r < 0)
log_full_errno(r == -EEXIST ? LOG_NOTICE : LOG_WARNING, r,
"Failed to populate /etc with preset unit settings, ignoring: %m");
Expand Down

0 comments on commit 9365158

Please sign in to comment.