From 589a4e665b6a73b97cd0fd6a0584511027c9431f Mon Sep 17 00:00:00 2001 From: Evan Goode Date: Tue, 27 Feb 2024 21:02:05 +0000 Subject: [PATCH] system-upgrade: Handle _execute errors --- dnf5.spec | 1 + dnf5/commands/offline/offline.cpp | 3 +++ .../system/dnf5-offline-transaction-cleanup.service | 10 ++++++++++ .../systemd/system/dnf5-offline-transaction.service | 1 + 4 files changed, 15 insertions(+) create mode 100644 dnf5/config/systemd/system/dnf5-offline-transaction-cleanup.service diff --git a/dnf5.spec b/dnf5.spec index b3e628401b..d63f94fcf3 100644 --- a/dnf5.spec +++ b/dnf5.spec @@ -663,6 +663,7 @@ config-manager, copr, and repoclosure commands. %files -n dnf5-plugins -f dnf5-plugin-builddep.lang -f dnf5-plugin-changelog.lang -f dnf5-plugin-config-manager.lang -f dnf5-plugin-copr.lang -f dnf5-plugin-needs-restarting.lang -f dnf5-plugin-repoclosure.lang %config %{_unitdir}/dnf5-offline-transaction.service +%config %{_unitdir}/dnf5-offline-transaction-cleanup.service %{_libdir}/dnf5/plugins/*.so %{_mandir}/man8/dnf5-builddep.8.* %{_mandir}/man8/dnf5-copr.8.* diff --git a/dnf5/commands/offline/offline.cpp b/dnf5/commands/offline/offline.cpp index 74767828d0..56e66dfd31 100644 --- a/dnf5/commands/offline/offline.cpp +++ b/dnf5/commands/offline/offline.cpp @@ -412,6 +412,9 @@ void OfflineExecuteCommand::run() { auto transaction = goal->resolve(); if (transaction.get_problems() != libdnf5::GoalProblem::NO_PROBLEM) { + std::cerr << "Failed to resolve transaction. This indicates some bigger problem, since the offline transaction " + "was already successfully resolved before. Was the cache at " + << datadir << " modified?" << std::endl; throw libdnf5::cli::GoalResolveError(transaction); } diff --git a/dnf5/config/systemd/system/dnf5-offline-transaction-cleanup.service b/dnf5/config/systemd/system/dnf5-offline-transaction-cleanup.service new file mode 100644 index 0000000000..4179eeb688 --- /dev/null +++ b/dnf5/config/systemd/system/dnf5-offline-transaction-cleanup.service @@ -0,0 +1,10 @@ +[Unit] +Description=Offline upgrade/transaction using DNF 5 failed +DefaultDependencies=no + +[Service] +Type=oneshot +# Remove the symlink if it's still there, to protect against reboot loops. +ExecStart=/usr/bin/rm -fv /system-update +# If anything goes wrong, reboot back to the normal system. +ExecStart=/usr/bin/systemctl --no-block reboot diff --git a/dnf5/config/systemd/system/dnf5-offline-transaction.service b/dnf5/config/systemd/system/dnf5-offline-transaction.service index 91a26b5e88..335e71165a 100644 --- a/dnf5/config/systemd/system/dnf5-offline-transaction.service +++ b/dnf5/config/systemd/system/dnf5-offline-transaction.service @@ -7,6 +7,7 @@ DefaultDependencies=no Requires=sysinit.target After=sysinit.target systemd-journald.socket system-update-pre.target Before=poweroff.target reboot.target shutdown.target system-update.target +OnFailure=dnf5-offline-transaction-cleanup.service [Service] # We are done when the script exits, not before