From 4df903783cfe6000e68a8088146414a313dc88ce Mon Sep 17 00:00:00 2001 From: Sven Sager Date: Tue, 22 Apr 2025 12:35:43 +0200 Subject: [PATCH] fix(revpiconfig): Ensure systemd reloads after unit changes Added systemd reload calls after unit enable/disable to reflect changes. Adjusted DBus method calls to capture and utilize change outputs effectively. This improves reliability in applying unit modifications. --- .../system_config/revpi_config.py | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/revpi_middleware/dbus_middleware1/system_config/revpi_config.py b/src/revpi_middleware/dbus_middleware1/system_config/revpi_config.py index 00c809d..45d2d26 100644 --- a/src/revpi_middleware/dbus_middleware1/system_config/revpi_config.py +++ b/src/revpi_middleware/dbus_middleware1/system_config/revpi_config.py @@ -665,13 +665,29 @@ def simple_systemd(action: ConfigActions, unit: str): systemd_manager = systemd["org.freedesktop.systemd1.Manager"] if action is ConfigActions.ENABLE: - systemd_manager.UnmaskUnitFiles([unit], False) - systemd_manager.EnableUnitFiles([unit], False, False) + # Dbus call: UnmaskUnitFiles(in as files, in b runtime, out a(sss) changes + lst_change_unmask = systemd_manager.UnmaskUnitFiles([unit], False) + + # Dbus call: EnableUnitFiles(in as files, in b runtime, in b force, + # out b carries_install_info, out a(sss) changes + lst_change_enable = systemd_manager.EnableUnitFiles([unit], False, False) + if lst_change_unmask or lst_change_enable: + # Reload systemd after modified unit property + systemd_manager.Reload() + + # Dbus call: StartUnit(in s name, in s mode, out o job systemd_manager.StartUnit(unit, "replace") elif action is ConfigActions.DISABLE: + + # Dbus call: StopUnit(in s name,in s mode, out o job systemd_manager.StopUnit(unit, "replace") - systemd_manager.DisableUnitFiles([unit], False) + + # Dbus call: DisableUnitFiles (in as files, in b runtime, out a(sss) changes) + change = systemd_manager.DisableUnitFiles([unit], False) + if change: + # Reload systemd after modified unit property + systemd_manager.Reload() elif action is ConfigActions.STATUS: try: @@ -696,6 +712,8 @@ def simple_systemd(action: ConfigActions, unit: str): else: raise ValueError(f"action {action} not supported") + return None + if __name__ == "__main__": rc = RevPiConfig()