Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement dnf5 needs-restarting plugin #887

Conversation

evan-goode
Copy link
Member

I'd like the DNF 5 needs-restarting command to behave a bit different from dnf4 needs-restarting. Here's what I propose:

  • dnf5 needs-restarting (no flag): I'd like this to simply report whether the system needs to be restarted. If there are "core packages" (such as kernel or glibc) that have been updated since boot, or if any advisory with the reboot_suggested flag applies to any of the packages that have been updated/installed since boot, dnf5 needs-restarting will list these packages and exit with code 1 to indicate a reboot is needed. Otherwise, it will exit with code 0. This proposed behavior is the same as the current behavior of dnf4 needs-restarting -r, but it would properly honor the reboot_suggested advisory rather than simply checking the hardcoded list of "core packages".

    I think this should be the default behavior of needs-restarting (rather than being behind a flag) because it's probably the most common use case. Here's an example of a user running needs-restarting when they needed needs-restarting -r: https://bugzilla.redhat.com/show_bug.cgi?id=2237223.

  • Regarding the behavior of dnf4 needs-restarting (no flag): currently, this command lists processes with open outdated files and recommends the user restart them. I think we should leave this behavior out of dnf5 needs-restarting for two reasons. First, tracer and dnf-plugins-extras-tracer implement this approach well, and we don't need to duplicate their functionality. Second, this whole strategy of looking for open files is a bit of a hack and IMO shouldn't be included in the core DNF plugins. It might work most of the time, but there are nuances and edge cases here, e.g. when a process maps a library without opening it: https://bugzilla.redhat.com/show_bug.cgi?id=1131307, or if, hypothetically, a process reads a file into memory, closes it, then encrypts the copy in memory. There's just no way to tell that the process is "using" that outdated file.

  • dnf5 needs-restarting -s: I'd like this to list systemd services that need to be restarted, but rather than check whether the service has any open outdated files, check the dependencies of the package that provides the service. I haven't implemented this yet in this PR, but here's an outline:

for each running systemd $service
    find the $package that provides the unit file for $service, if any
        recursively get all $dependencies of $package
        if $package or any $dependency has been updated since $service started
            recommend restart of $service

For #743

Resolves #587

@evan-goode evan-goode self-assigned this Sep 15, 2023
@ppisar
Copy link
Contributor

ppisar commented Sep 18, 2023

dnf5 needs-restarting will list these packages and exit with code 1 to indicate a reboot is needed.

Would it be possible the reverse the exit codes? Now the codes match to "does-not-need-restart" question.

@evan-goode
Copy link
Member Author

dnf5 needs-restarting will list these packages and exit with code 1 to indicate a reboot is needed.

Would it be possible the reverse the exit codes? Now the codes match to "does-not-need-restart" question.

Hmm, yes using code 0 (truthy) to mean "no restart" does make scripts read a bit awkward, I see your point:

if dnf5 needs-restarting; then
  echo The system DOES NOT need a reboot
fi

Similar tools like tracer, Debian's checkrestart, and dnf4 needs-restarting use these exit codes though, so I think still it would be best to keep consistent with them. checkrestart mentions the exit code may be consumed by monitoring tools like Nagios, where the convention is "exit zero is good".

I think of "no reboot needed" as the default, unsurprising, comfortable result and "reboot needed" as the less common result that needs to be handled. The exit codes make more sense from that perspective.

The new behavior of `dnf5 needs-restarting --services` still lists
systemd services that should be restarted following an upgrade, but
instead of checking open files like dnf4 needs-restarting, it checks
whether any dependency of the package that provides the service has been
updated since the service started.
dnf4 needs-restarting's logic to get the boot time doesn't work when the
RTC exists but gives unreliable information (e.g. it's not in UTC). When
systemd is available, we should just ask systemd when the system booted.

When systemd is not available, we are likely in a container, and stat
/proc/1 will probably yield a correct answer.
@evan-goode evan-goode marked this pull request as ready for review November 1, 2023 21:34
@evan-goode
Copy link
Member Author

Alright, I think this is ready for review now.

@jan-kolarik jan-kolarik assigned jan-kolarik and unassigned evan-goode Nov 2, 2023
dnf5-plugins/needs_restarting_plugin/CMakeLists.txt Outdated Show resolved Hide resolved
dnf5-plugins/needs_restarting_plugin/needs_restarting.cpp Outdated Show resolved Hide resolved
dnf5-plugins/needs_restarting_plugin/needs_restarting.cpp Outdated Show resolved Hide resolved
dnf5-plugins/needs_restarting_plugin/needs_restarting.cpp Outdated Show resolved Hide resolved
dnf5-plugins/needs_restarting_plugin/needs_restarting.cpp Outdated Show resolved Hide resolved
libdnf5/rpm/package_query.cpp Outdated Show resolved Hide resolved
doc/dnf5_plugins/index.rst Show resolved Hide resolved
libdnf5/rpm/package_query.cpp Outdated Show resolved Hide resolved
@jan-kolarik
Copy link
Member

LGTM, thanks for the cooperation! 🙂

One more thing: as already mentioned, the existing tests in the CI stack do not cover all functionalities provided by this new DNF5 version of the needs-restarting plugin, particularly regarding the reboot suggested packages. I believe the updateinfo metadata can be mocked for this purpose, allowing us to create testing data and write the necessary tests using the current state of the CI stack.

Please create a follow-up issue in the CI stack to ensure we address this.

@jan-kolarik
Copy link
Member

Oh, I just realized that the existing tests aren't being executed for dnf5 at the moment. We should attempt to reuse at least some of them.

evan-goode added a commit to evan-goode/ci-dnf-stack that referenced this pull request Nov 8, 2023
Update the needs-restarting tests for DNF 5 and add a test for
recommending a reboot when a package has an associated reboot_suggested
advisory.

Requires rpm-software-management/dnf5#887

For rpm-software-management/dnf5#743
@evan-goode
Copy link
Member Author

CI PR: rpm-software-management/ci-dnf-stack#1403

Copy link
Contributor

@kontura kontura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple minor typos, otherwise LGTM.

Also I believe the changes in rpm/nevra.hpp are technically not longer needed but we can keep them if you think they might be useful in the future.

doc/changes.rst Outdated Show resolved Hide resolved
filter_reboot_suggested was binary searching the results of
get_advisory_packages_sorted_by_name_arch_evr() assuming they were
sorted according to cmp_naevr, however that function actually returns
packages sorted by the libsolv ids of name, arch, and evr, not the
string representations of name, arch, and evr like cmp_naevr does.
@evan-goode
Copy link
Member Author

Just a couple minor typos, otherwise LGTM.

Also I believe the changes in rpm/nevra.hpp are technically not longer needed but we can keep them if you think they might be useful in the future.

True, I think we might as well keep them.

@jan-kolarik
Copy link
Member

I just noticed the tmp commit present in the PR, probably an oversight... 🙂

DNF 4 needs-restarting -r has essentially the same behavior as DNF 5 needs-restarting
with no flag, so the flag should be kept in as a no-op for backwards compatibility.
@evan-goode
Copy link
Member Author

I just noticed the tmp commit present in the PR, probably an oversight... 🙂

Sigh... thank you. One more force push...

@jan-kolarik
Copy link
Member

I just noticed the tmp commit present in the PR, probably an oversight... 🙂

Sigh... thank you. One more force push...

Great and thank you for your patience with such an exhaustive review 🙂 I believe we can proceed with the merge now, as Ales mentioned only minor typos.

@jan-kolarik jan-kolarik added this pull request to the merge queue Nov 9, 2023
Merged via the queue into rpm-software-management:main with commit 419fed5 Nov 9, 2023
7 checks passed
evan-goode added a commit to evan-goode/ci-dnf-stack that referenced this pull request Nov 14, 2023
Update the needs-restarting tests for DNF 5 and add a test for
recommending a reboot when a package has an associated reboot_suggested
advisory.

Requires rpm-software-management/dnf5#887

For rpm-software-management/dnf5#743
evan-goode added a commit to evan-goode/ci-dnf-stack that referenced this pull request Nov 14, 2023
Update the needs-restarting tests for DNF 5 and add a test for
recommending a reboot when a package has an associated reboot_suggested
advisory.

Requires rpm-software-management/dnf5#887

For rpm-software-management/dnf5#743
evan-goode added a commit to evan-goode/ci-dnf-stack that referenced this pull request Nov 14, 2023
Update the needs-restarting tests for DNF 5 and add a test for
recommending a reboot when a package has an associated reboot_suggested
advisory.

Requires rpm-software-management/dnf5#887

For rpm-software-management/dnf5#743
jan-kolarik pushed a commit to rpm-software-management/ci-dnf-stack that referenced this pull request Nov 15, 2023
Update the needs-restarting tests for DNF 5 and add a test for
recommending a reboot when a package has an associated reboot_suggested
advisory.

Requires rpm-software-management/dnf5#887

For rpm-software-management/dnf5#743
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Implement logic to check whether package requires system reboot
4 participants