Skip to content

Commit

Permalink
05core: remove automatic reboot after timeout
Browse files Browse the repository at this point in the history
The reboot and consequently the timeout masked valuable debug
information. The reboot also caused some cascading errors due to the
fact that the system would try and run as if all required dependencies
were satisfied during the first boot.

Closes coreos/fedora-coreos-tracker#928.
  • Loading branch information
prestist committed Apr 22, 2022
1 parent 13106a6 commit 279292a
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# Before starting the emergency shell, prompt the user to press Enter.
# If they don't, reboot the system.
#
# Assumes /bin/sh is bash.
# Display relevant errors then enter emergency shell

# _wait_for_journalctl_to_stop will block until either:
# - no messages have appeared in journalctl for the past 5 seconds
Expand All @@ -22,13 +19,7 @@ _wait_for_journalctl_to_stop() {
done
}

_prompt_for_timeout() {
local timeout=300
local interval=15

if [[ -e /.emergency-shell-confirmed ]]; then
return
fi
_display_relevant_errors() {
failed=$(systemctl --failed --no-legend --plain | cut -f 1 -d ' ')
if [ -n "${failed}" ]; then
# Something failed, suppress kernel logs so that it's more likely
Expand Down Expand Up @@ -77,41 +68,9 @@ EOF
done
fi
fi

# Regularly prompt with time remaining. This ensures the prompt doesn't
# get lost among kernel and systemd messages, and makes it clear what's
# going on if the user just connected a serial console.
while [[ $timeout > 0 ]]; do
local m=$(( $timeout / 60 ))
local s=$(( $timeout % 60 ))
local m_label="minutes"
if [[ $m = 1 ]]; then
m_label="minute"
fi

if [[ $s != 0 ]]; then
echo -n -e "Press Enter for emergency shell or wait $m $m_label $s seconds for reboot. \r"
else
echo -n -e "Press Enter for emergency shell or wait $m $m_label for reboot. \r"
fi

local anything
if read -t $interval anything; then
> /.emergency-shell-confirmed
return
fi
timeout=$(( $timeout - $interval ))
done

echo -e "\nRebooting."
# This is not very nice, but since reboot.target likely conflicts with
# the existing goal target wrt the desired state of shutdown.target,
# there doesn't seem to be a better option.
systemctl reboot --force
exit 0
}

# If we're invoked from a dracut breakpoint rather than
# dracut-emergency.service, we won't have a controlling terminal and stdio
# won't be connected to it. Explicitly read/write /dev/console.
_prompt_for_timeout < /dev/console > /dev/console
_display_relevant_errors < /dev/console > /dev/console
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ install() {
date \
dd

inst_hook emergency 99 "${moddir}/timeout.sh"
inst_hook emergency 99 "${moddir}/emergency-shell.sh"

inst_script "$moddir/ignition-virtio-dump-journal.sh" "/usr/bin/ignition-virtio-dump-journal"
install_unit_wants ignition-virtio-dump-journal.service emergency.target
Expand Down

0 comments on commit 279292a

Please sign in to comment.