diff --git a/dracut/99emergency-timeout/ignition-virtio-dump.service b/dracut/99emergency-timeout/ignition-virtio-dump.service new file mode 100644 index 0000000..31874cc --- /dev/null +++ b/dracut/99emergency-timeout/ignition-virtio-dump.service @@ -0,0 +1,13 @@ +[Unit] +Description=Ignition (virtio dump) +Documentation=https://github.com/coreos/ignition +ConditionPathExists=/etc/initrd-release +DefaultDependencies=false +After=basic.target + +[Service] +Type=oneshot +RemainAfterExit=yes +EnvironmentFile=/run/ignition.env +ExecStart=/usr/bin/virtio-dump + diff --git a/dracut/99emergency-timeout/module-setup.sh b/dracut/99emergency-timeout/module-setup.sh index 26ac01a..d676a7f 100755 --- a/dracut/99emergency-timeout/module-setup.sh +++ b/dracut/99emergency-timeout/module-setup.sh @@ -2,10 +2,22 @@ # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh +install_unit_wants() { + local unit="$1"; shift + local target="$1"; shift + local instantiated="${1:-$unit}"; shift + inst_simple "$moddir/$unit" "$systemdsystemunitdir/$unit" + mkdir -p "$initdir/$systemdsystemunitdir/$target.wants" + ln_r "../$unit" "$systemdsystemunitdir/$target.wants/$instantiated" +} + install() { inst_multiple \ cut \ date inst_hook emergency 99 "${moddir}/timeout.sh" + + inst_script "$moddir/virtio-dump.sh" "/usr/bin/virtio-dump" + install_unit_wants ignition-virtio-dump.service emergency.target } diff --git a/dracut/99emergency-timeout/virtio-dump.sh b/dracut/99emergency-timeout/virtio-dump.sh new file mode 100755 index 0000000..46a9a64 --- /dev/null +++ b/dracut/99emergency-timeout/virtio-dump.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -euo pipefail + +port=/dev/virtio-ports/com.coreos.ignition.journal +if [ -e "${port}" ]; then + journalctl -o json > "${port}" + # And this signals end of stream + echo '{}' > "${port}" +else + echo "Didn't find virtio port ${port}" +fi