forked from rpms/dnf-plugins-core
63 lines
2.6 KiB
Diff
63 lines
2.6 KiB
Diff
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
|
|
|