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

Add reboot option to DNF Automatic #1879

Merged
merged 4 commits into from
Jan 26, 2023

Conversation

evan-goode
Copy link
Member

Add ability in DNF Automatic to automatically trigger a reboot after an upgrade. The reboot option supports three settings: never does not reboot the system (current behavior). when-changed triggers a reboot after any upgrade. when-needed triggers a reboot only when rebooting is necessary to apply changes, such as when systemd or the kernel is upgraded.

Then when-needed option follows dnf needs-restarting's approach for determining whether a reboot is needed; we just look to see whether any "core" packages are involved in the transaction, e.g. the kernel, systemd, dbus, glibc.

I'm still not sure the best way to write a test for this feature, maybe someone has suggestions.

See https://bugzilla.redhat.com/show_bug.cgi?id=2124793

@evan-goode evan-goode marked this pull request as ready for review January 23, 2023 14:01
@inknos inknos self-assigned this Jan 23, 2023
@inknos
Copy link
Contributor

inknos commented Jan 24, 2023

Hey, I am looking at the PR and the first thing that comes up is the commit message.
Please, could you rewrite the commit following this?
Another thing that we use to do is to add the bug in the commit title like (RhBug:xxxxxxx). So the final would be:

Add reboot option to DNF Automatic (RhBug:2124793)

= changelog =
msg: Long message...
type: bugfix
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2124793

Add ability in DNF Automatic to automatically trigger a reboot after an
upgrade. The `reboot` option supports three settings: ``never`` does not
reboot the system (current behavior). ``when-changed`` triggers a reboot
after any upgrade. ``when-needed`` triggers a reboot only when rebooting
is necessary to apply changes, such as when systemd or the kernel is
upgraded. The `reboot_command` option allows customizing the command
used to reboot (default is `shutdown -r`).

= changelog =
msg: Add `reboot` option to DNF Automatic
type: enhancement
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2124793
@evan-goode
Copy link
Member Author

Thanks, done.

reboot = never

# The command that is run to trigger a system reboot.
reboot_command = "shutdown -r"
Copy link
Contributor

Choose a reason for hiding this comment

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

I was testing your code today, and I was thinking whether our ci is suitable or not for testing what you want. Probably, there is no simple way to trigger a reboot, but there are other options.
Since you set a custom command here, I would think of another way to test the reboot trigger.

Maybe, during behave tests, you could set an arbitrary command in etc/dnf/automatic.conf. Let's say that instead of shutdown -r you touch some file, then you can check if the file exists and have the trigger tested. Unfortunately this is the only partial solution I came up with.

Choose a reason for hiding this comment

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

FTR: Cockpit's updates page delays the shutdown by a bit, so that logged in users get a warning and have some time to orderly stop their work. That's a good thing to do on servers IMHO.

That same thing also allows you to test this feature relatively painlessly: It's enough time to validate that a shutdown was scheduled and cancel it again (like in our tests). That avoids the costly (time) or impossible (Testing Farm/gating tests) actual reboot.

Copy link
Contributor

Choose a reason for hiding this comment

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

FTR: Cockpit's updates page delays the shutdown by a bit, so that logged in users get a warning and have some time to orderly stop their work. That's a good thing to do on servers IMHO

That's a good idea.

That same thing also allows you to test this feature relatively painlessly

That does not apply for dnf, since we run our tests in containers. But you cannot really test if a system reboots universally. Say that a system does not have the shutdown command, then the only thing you can test is to check if the hook triggers. It would be the user/sysadmin/distro responsibility to configure the conf file accordingly.

Said that, it's not a big deal imho since we are not testing the capability of shutdown -r of rebooting the system.

It's enough time to validate that a shutdown was scheduled and cancel it again

I think this would be the solution in most cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

FTR: Cockpit's updates page delays the shutdown by a bit, so that logged in users get a warning and have some time to orderly stop their work. That's a good thing to do on servers IMHO.

Thanks for the input, I've made the default reboot_command add a 5-minute delay and wall message.

@inknos how does rpm-software-management/ci-dnf-stack#1210 look? I set the reboot_command to echo a certain string, then check that stdout contains that string. Maybe touching a file is a more reliable way to make sure the command is actually run, but I think this should be sufficient.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the stoud approach, I will post some comments about the CI PR and then I believe this is good to go. Thank you

# List taken from DNF needs-restarting
need_reboot = frozenset(('kernel', 'kernel-rt', 'glibc',
'linux-firmware', 'systemd', 'dbus',
'dbus-broker', 'dbus-daemon'))
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to share this set with needs-restarting plugin somehow.
One option would be a new config option. In this case it should be implemented also for dnf5.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm true, would doing this via a new config option require a change in libdnf?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, if we agree that it is useful, it will be spread across libdnf, dnf, dnf-plugins-core, and dnf5 :)
But I'm not gonna block this PR because of that. It could be done in subsequent patches.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I think we can hold off for now and err on the side of minimal changes. Hopefully this list doesn't change too much over the years. But it would be good for it to be configurable by the user.

@evan-goode
Copy link
Member Author

I think we are good to merge now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants