From aa8839d0728a7d2936a13041c7fb13eca09e2788 Mon Sep 17 00:00:00 2001 From: Stephen Lowrie Date: Mon, 15 Mar 2021 23:23:13 -0500 Subject: [PATCH] examples: add ignition-kargs binary example --- examples/ignition-kargs-helper | 45 +++++++++++++++++++++++++++++++++ examples/ignition-kargs.service | 22 ++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100755 examples/ignition-kargs-helper create mode 100644 examples/ignition-kargs.service diff --git a/examples/ignition-kargs-helper b/examples/ignition-kargs-helper new file mode 100755 index 0000000000..460e8f2b91 --- /dev/null +++ b/examples/ignition-kargs-helper @@ -0,0 +1,45 @@ +#!/bin/bash + +set -euxo pipefail + +# Mount /boot. Note that we mount /boot but we don't unmount it because we +# are run in a systemd unit with MountFlags=slave so it is unmounted for us. +bootmnt=/mnt/boot_partition +mkdir -p ${bootmnt} +bootdev=/dev/disk/by-label/boot +mount -o rw ${bootdev} ${bootmnt} +grubcfg="${bootmnt}/grub/grub.cfg" + +kernelopts="$(grep kernelopts= <$grubcfg)" + +while [[ $# -gt 0 ]] +do +key="$1" + +case $key in +--should-exist) + arg="$2" + # don't repeat the arg + if [[ ! " ${kernelopts[*]} " =~ " ${arg} " ]]; then + kernelopts="$kernelopts $arg " + fi + shift 2 + ;; +--should-not-exist) + arg="$2" + kernelopts="$(echo "$kernelopts" | sed "s|$2||g")" + shift 2 + ;; + *) + echo "Unknown option" + exit 1 + ;; +esac +done + +# only apply the changes & reboot if changes have been made +if [[ ! "$kernelopts" == "$(grep kernelopts= <$grubcfg)" ]]; then + awk "{sub(/kernelopts=.*/,\"$kernelopts\"); print}" $grubcfg > tmp && mv tmp $grubcfg + + systemctl reboot +fi diff --git a/examples/ignition-kargs.service b/examples/ignition-kargs.service new file mode 100644 index 0000000000..75cbb39a10 --- /dev/null +++ b/examples/ignition-kargs.service @@ -0,0 +1,22 @@ +[Unit] +Description=Ignition (kargs) +Documentation=https://github.com/coreos/ignition +ConditionPathExists=/etc/initrd-release +DefaultDependencies=false +Before=ignition-complete.target + +# Stage order: setup -> fetch-offline [-> fetch] [-> kargs] -> disks -> mount -> files. +After=ignition-fetch.service +Before=ignition-disks.service + +OnFailure=emergency.target +OnFailureJobMode=isolate + +[Service] +Type=oneshot +RemainAfterExit=yes +EnvironmentFile=/run/ignition.env +ExecStart=/usr/bin/ignition --root=/sysroot --platform=${PLATFORM_ID} --stage=kargs +# MountFlags=slave is so the umount of /boot is guaranteed to happen. +# /boot will only be mounted for the lifetime of the unit. +MountFlags=slave