Skip to content

Commit

Permalink
auto-detect image type and use correct rollback
Browse files Browse the repository at this point in the history
greenboot will able able to detect the image type of the os,
i.e ostree or bootc and use the correct verb to rollback to
previous stable deployment.

Signed-off-by: saypaul <[email protected]>
  • Loading branch information
say-paul committed Aug 12, 2024
1 parent 1c1a927 commit 24884c1
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions usr/libexec/greenboot/greenboot-rpm-ostree-grub2-check-fallback
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,32 @@ function remount_boot_ro {
return
}

function attempt_rollback {
# Check if the bootc command is available
if command -v bootc &> /dev/null; then
status_type=$(bootc status --booted --json 2>/dev/null | jq -r .status.type 2>/dev/null)
if [ "$status_type" == "bootcHost" ]; then
bootc rollback
echo "<3>FALLBACK BOOT DETECTED! Default bootc deployment has been rolled back."
fi
return
fi
# Check if its ostree based os
if [-f /run/ostree-booted]; then

Check notice

Code scanning / shellcheck

The mentioned syntax error was in this if expression. Note

The mentioned syntax error was in this if expression.

Check failure

Code scanning / shellcheck

You need a space after the [ and before the ]. Error

You need a space after the [ and before the ].

Check failure

Code scanning / shellcheck

Couldn't parse this test expression. Fix to allow more checks. Error

Couldn't parse this test expression. Fix to allow more checks.

Check failure

Code scanning / shellcheck

Expected this to be an argument to the unary condition. Error

Expected this to be an argument to the unary condition.

Check failure

Code scanning / shellcheck

You need a space before the ]. Error

You need a space before the ].

Check failure

Code scanning / shellcheck

Missing space before ]. Fix any mentioned problems and try again. Error

Missing space before ]. Fix any mentioned problems and try again.
rpm-ostree rollback
echo "<3>FALLBACK BOOT DETECTED! Default rpm-ostree deployment has been rolled back."
return
fi
echo "<3>Rollback is only supported in ostree or bootc based os."
return
}

# Determine if the current boot is a fallback boot
# If booted into fallback deployment, clean up bootloader entries (rollback)
if grub2-editenv list | grep -q "^boot_counter=-1$"; then
# Logs from previous boot may be unavailable on systems without internal RTC; defaulting to empty string
prev_logs="$(journalctl -u greenboot-healthcheck.service -p 2 -b -1 -o cat)" || true
rpm-ostree rollback
echo "<3>FALLBACK BOOT DETECTED! Default rpm-ostree deployment has been rolled back."
attempt_rollback
if [ -n "$prev_logs" ]; then
echo "<3>Health check logs from previous boot:"
echo "<3>$prev_logs"
Expand Down

0 comments on commit 24884c1

Please sign in to comment.