Skip to content
This repository has been archived by the owner on Aug 25, 2021. It is now read-only.

Conditionalize units which require a boot disk #102

Merged
merged 3 commits into from
Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions dracut/30ignition/ignition-diskful.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This target contains Ignition units that should only run when we have a
# boot disk, i.e. when we're not running diskless from a live image in RAM.
# Like ignition-complete.target, it only runs on first boot.
[Unit]
Description=Ignition Boot Disk Setup
Before=initrd.target

# Make sure if any ExecStart= fail, the boot fails. This normally would
# already be guaranteed by `initrd.target` failing, but that doesn't seem to be
# enough: https://bugzilla.redhat.com/show_bug.cgi?id=1696796
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks to be copied from igniton-complete.target. According to the BZ the bug only affects f29 so maybe we can drop this now? cc @jlebon as this was first added in 549002e

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried dropping the stanza from ignition-complete.target, and that causes systemd to loop in the initrd if ignition-files fails. With the stanza, it properly fails the boot. So, still needed.

On the other hand, if a dependency of ignition-diskful.target fails, systemd doesn't fail the boot with or without this stanza. 🙁

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I recalled this working on f30. I guess systemd might've regressed on git master too? If that's the case, we should be able to file an issue upstream for this where it'll hopefully get more exposure. (The only reason I made it an RHBZ was that upstream only wants bugs that reproduce against N and N-1).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would definitely be nice if we could get this fixed in at least f31

OnFailure=emergency.target
OnFailureJobMode=isolate

# Make sure we stop all the units before switching root
Conflicts=initrd-switch-root.target umount.target
Conflicts=dracut-emergency.service emergency.service emergency.target
6 changes: 6 additions & 0 deletions dracut/30ignition/ignition-generator
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ add_requires() {
# boot.
if $(cmdline_bool 'ignition.firstboot' 0); then
add_requires ignition-complete.target

# Invoke distro hook for detecting whether we're booted from a live image,
# and therefore won't have a root disk.
if ! command -v is-live-image >/dev/null || ! is-live-image; then
add_requires ignition-diskful.target
fi
fi

echo "PLATFORM_ID=$(cmdline_arg ignition.platform.id)" > /run/ignition.env
22 changes: 13 additions & 9 deletions dracut/30ignition/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ depends() {
echo qemu systemd url-lib network
}

# target is optional, used for instantiated units
install_ignition_unit() {
unit=$1; shift
target="${1:-$unit}"
local unit="$1"; shift
local target="${1:-ignition-complete.target}"; shift
local instantiated="${1:-$unit}"; shift
inst_simple "$moddir/$unit" "$systemdsystemunitdir/$unit"
ln_r "../$unit" "$systemdsystemunitdir/ignition-complete.target.requires/$target"
mkdir -p "$initdir/$systemdsystemunitdir/$target.requires"
ln_r "../$unit" "$systemdsystemunitdir/$target.requires/$instantiated"
}

install() {
Expand Down Expand Up @@ -54,16 +55,19 @@ install() {
inst_simple "$moddir/ignition-complete.target" \
"$systemdsystemunitdir/ignition-complete.target"

mkdir -p "$initdir/$systemdsystemunitdir/ignition-complete.target.requires"
inst_simple "$moddir/ignition-diskful.target" \
"$systemdsystemunitdir/ignition-diskful.target"

# path generated by systemd-escape --path /dev/disk/by-label/root
install_ignition_unit [email protected] 'coreos-gpt-setup@dev-disk-by\x2dlabel-root.service'
install_ignition_unit ignition-setup-base.service
install_ignition_unit ignition-setup-user.service
install_ignition_unit ignition-disks.service
install_ignition_unit ignition-mount.service
install_ignition_unit ignition-files.service
install_ignition_unit ignition-remount-sysroot.service

# units only started when we have a boot disk
Copy link
Member

@cgwalters cgwalters Sep 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if it'd be cleaner to have the units test ConditionPathExists=!/run/ostree-live instead? I don't have a strong opinion though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these except ignition-remount-sysroot.service pull in device dependencies, so they have to be enabled via generator. Conditions are only evaluated after dependencies are pulled in.

# path generated by systemd-escape --path /dev/disk/by-label/root
install_ignition_unit [email protected] ignition-diskful.target 'coreos-gpt-setup@dev-disk-by\x2dlabel-root.service'
install_ignition_unit ignition-setup-user.service ignition-diskful.target
install_ignition_unit ignition-remount-sysroot.service ignition-diskful.target

# needed for openstack config drive support
inst_rules 60-cdrom_id.rules
Expand Down
1 change: 1 addition & 0 deletions systemd/ignition-firstboot-complete.service
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Description=Mark boot complete
Documentation=https://github.com/coreos/ignition
ConditionKernelCommandLine=ignition.firstboot
ConditionPathExists=!/run/ostree-live
RequiresMountsFor=/boot

[Service]
Expand Down