needs-restarting prefers to obtain a boot time from systemd to deal with RTCs running in local time

This commit is contained in:
Petr Písař 2024-05-06 15:30:16 +02:00 committed by root
parent 4f5d16cec7
commit e69b515d87
5 changed files with 195 additions and 1 deletions

View File

@ -0,0 +1 @@
d9a1561a5c4d238340b3db6d081c70b86841c291 dnf-plugins-core-4.3.0.tar.gz

View File

@ -0,0 +1,62 @@
From 74ed4833064ecfec2ac51471d4dfddc86f64d11b Mon Sep 17 00:00:00 2001
From: Nicola Sella <nsella@redhat.com>
Date: Wed, 13 Mar 2024 13:27:54 +0100
Subject: [PATCH 1/3] needs-restarting: get systemd boot time from
UnitsLoadStartTimestamp
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Upstream commit: 74de8fe84679e509b16ca1d3f12b7d292210ca27
Resolves: https://issues.redhat.com/browse/RHEL-14900
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
plugins/needs_restarting.py | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/plugins/needs_restarting.py b/plugins/needs_restarting.py
index 309a216..2662d2d 100644
--- a/plugins/needs_restarting.py
+++ b/plugins/needs_restarting.py
@@ -215,6 +215,11 @@ class ProcessStart(object):
We have two sources from which to derive the boot time. These values vary
depending on containerization, existence of a Real Time Clock, etc.
For our purposes we want the latest derived value.
+ - UnitsLoadStartTimestamp property on /org/freedesktop/systemd1
+ The start time of the service manager, according to systemd itself.
+ Seems to be more reliable than UserspaceTimestamp when the RTC is
+ in local time. Works unless the system was not booted with systemd,
+ such as in (most) containers.
- st_mtime of /proc/1
Reflects the time the first process was run after booting
This works for all known cases except machines without
@@ -225,6 +230,25 @@ class ProcessStart(object):
Does not work on containers which share their kernel with the
host - there the host kernel uptime is returned
"""
+ units_load_start_timestamp = None
+ try:
+ bus = dbus.SystemBus()
+ systemd1 = bus.get_object(
+ 'org.freedesktop.systemd1',
+ '/org/freedesktop/systemd1'
+ )
+ props = dbus.Interface(
+ systemd1,
+ dbus.PROPERTIES_IFACE
+ )
+ units_load_start_timestamp = props.Get(
+ 'org.freedesktop.systemd1.Manager',
+ 'UnitsLoadStartTimestamp'
+ )
+ if units_load_start_timestamp != 0:
+ return int(units_load_start_timestamp / (1000 * 1000))
+ except dbus.exceptions.DBusException as e:
+ logger.debug("D-Bus error getting boot time from systemd: {}".format(e))
proc_1_boot_time = int(os.stat('/proc/1').st_mtime)
if os.path.isfile('/proc/uptime'):
--
2.45.0

View File

@ -0,0 +1,58 @@
From 28f2f9876b85fc73f749ba347b0c280a6acbda7e Mon Sep 17 00:00:00 2001
From: Nicola Sella <nsella@redhat.com>
Date: Wed, 27 Mar 2024 16:34:11 +0100
Subject: [PATCH 2/3] Document needs-restarting boot time
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Upstream commit: a0ac8717219a1ec9f466162e87f40afa9aa65284
Also, add a warning in the docs if the system is running in RTC
Resolves: https://issues.redhat.com/browse/RHEL-14900
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
doc/needs_restarting.rst | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/doc/needs_restarting.rst b/doc/needs_restarting.rst
index 46cbcb0..379d027 100644
--- a/doc/needs_restarting.rst
+++ b/doc/needs_restarting.rst
@@ -35,6 +35,32 @@ Description
Note that in most cases a process should survive update of its binary and libraries it is using without requiring to be restarted for proper operation. There are however specific cases when this does not apply. Separately, processes often need to be restarted to reflect security updates.
+.. note::
+ Needs restarting will try to guess the boot time using three different methods:
+
+ ``UnitsLoadStartTimestamp``
+ property on ``/org/freedesktop/systemd1``.
+ Works unless the system was not booted with systemd,
+ such as in (most) containers.
+ ``st_mtime of /proc/1``
+ Reflects the time the first process was run after booting
+ This works for all known cases except machines without
+ a RTC - they awake at the start of the epoch.
+ ``/proc/uptime``
+ Seconds field of /proc/uptime subtracted from the current time
+ Works for machines without RTC if the current time is reasonably correct.
+ Does not work on containers which share their kernel with the
+ host - there the host kernel uptime is returned
+
+
+.. warning::
+ When the system is configured to read the RTC time in the local time zone.
+ This mode cannot be fully supported. It will create various problems
+ with time zone changes and daylight saving time adjustments. The RTC
+ time is never updated, it relies on external facilities to maintain it.
+ **If at all possible, use RTC in UTC by calling**
+ ``timedatectl set-local-rtc 0``.
+
-------
Options
-------
--
2.45.0

View File

@ -0,0 +1,66 @@
From a4d62516adc69b01681e6832ae265aa4865e671f Mon Sep 17 00:00:00 2001
From: Evan Goode <mail@evangoo.de>
Date: Wed, 27 Mar 2024 17:47:52 +0000
Subject: [PATCH 3/3] Needs-restarting: punctuation edits
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Upstream commit: 486e9d4d7f03309f3eaf71e297ae956e18357bd8
Resolves: https://issues.redhat.com/browse/RHEL-14900
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
doc/needs_restarting.rst | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/doc/needs_restarting.rst b/doc/needs_restarting.rst
index 379d027..dafcdd1 100644
--- a/doc/needs_restarting.rst
+++ b/doc/needs_restarting.rst
@@ -36,30 +36,30 @@ Description
Note that in most cases a process should survive update of its binary and libraries it is using without requiring to be restarted for proper operation. There are however specific cases when this does not apply. Separately, processes often need to be restarted to reflect security updates.
.. note::
- Needs restarting will try to guess the boot time using three different methods:
+ Needs-restarting will try to guess the boot time using three different methods:
``UnitsLoadStartTimestamp``
- property on ``/org/freedesktop/systemd1``.
+ D-Bus property on ``/org/freedesktop/systemd1``.
Works unless the system was not booted with systemd,
such as in (most) containers.
``st_mtime of /proc/1``
- Reflects the time the first process was run after booting
+ Reflects the time the first process was run after booting.
This works for all known cases except machines without
- a RTC - they awake at the start of the epoch.
+ a RTC—they awake at the start of the epoch.
``/proc/uptime``
- Seconds field of /proc/uptime subtracted from the current time
+ Seconds field of ``/proc/uptime`` subtracted from the current time.
Works for machines without RTC if the current time is reasonably correct.
Does not work on containers which share their kernel with the
- host - there the host kernel uptime is returned
+ host—there, the host kernel uptime is returned.
.. warning::
- When the system is configured to read the RTC time in the local time zone.
- This mode cannot be fully supported. It will create various problems
- with time zone changes and daylight saving time adjustments. The RTC
- time is never updated, it relies on external facilities to maintain it.
- **If at all possible, use RTC in UTC by calling**
- ``timedatectl set-local-rtc 0``.
+ Some systems are configured to read the RTC time in the local time
+ zone. This mode cannot be fully supported. It will create various problems
+ with time zone changes and daylight saving time adjustments. The RTC time
+ is never updated, it relies on external facilities to maintain it. **If at
+ all possible, use RTC in UTC by calling** ``timedatectl set-local-rtc 0``.
+ See ``man timedatectl`` for more information.
-------
Options
--
2.45.0

View File

@ -34,7 +34,7 @@
Name: dnf-plugins-core
Version: 4.3.0
Release: 13%{?dist}
Release: 14%{?dist}
Summary: Core Plugins for DNF
License: GPLv2+
URL: https://github.com/rpm-software-management/dnf-plugins-core
@ -53,6 +53,9 @@ Patch11: 0011-Update-translations-RHEL-9.3.patch
Patch12: 0012-RHEL-6394-Fix-incorrect-spanish-translation-file.patch
Patch13: 0013-Fix-for-issue-with-binary-garbage-in-smaps-files.patch
Patch14: 0014-needs-restarting-Add-microcode_ctl-to-a-reboot-list.patch
Patch15: 0015-needs-restarting-get-systemd-boot-time-from-UnitsLoa.patch
Patch16: 0016-Document-needs-restarting-boot-time.patch
Patch17: 0017-Needs-restarting-punctuation-edits.patch
BuildArch: noarch
BuildRequires: cmake
@ -800,6 +803,10 @@ ln -sf %{_mandir}/man1/%{yum_utils_subpackage_name}.1.gz %{buildroot}%{_mandir}/
%endif
%changelog
* Mon May 06 2024 Petr Pisar <ppisar@redhat.com> - 4.3.0-14
- needs-restarting prefers to obtain a boot time from systemd to deal with
RTCs running in local time (RHEL-14900)
* Mon Jan 15 2024 Petr Pisar <ppisar@redhat.com> - 4.3.0-13
- Add microcode_ctl to a reboot list (RHEL-4600)