From 2ceb80607a5b65607b0a8d9daf9e09a2d25cfdb6 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Mon, 7 Apr 2025 13:56:22 -0700 Subject: [PATCH] setup: Perform package operations immediately on trigger - Operations triggered by FreedomBox service itself such 'apt-get update' and 'apt-get install' don't cause the package operations (post-install and post-update) to get triggered. This is due to recent implementation of a check with the FREEDOMBOX_INVOKED environment variable. So, it fairly safe to attempt these operations immediately as they would have been invoked from outside. - In one case, when unattended-upgrades is triggered it could lead to post-install trigger getting triggered too quickly. But this only leads the operation detecting that apt is busy and performing the long wait immediately after. - In case of distribution upgrade, this could mean simpler reasoning and less wait time. Tests: - When a package is installed, post-dpkg operations are triggered and completed immediately. However, another apt process immediately takes lock, this results in a waiting period. - When a 'apt update' is run, update operations are triggered and completed immediately. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/setup.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/plinth/setup.py b/plinth/setup.py index a7fcef3e6..a90e3f3f4 100644 --- a/plinth/setup.py +++ b/plinth/setup.py @@ -469,12 +469,6 @@ class ForceUpgrader(): """ for _ in range(self.UPGRADE_ATTEMPTS): - logger.info('Waiting for %s seconds before attempting upgrade', - self.UPGRADE_ATTEMPT_WAIT_SECONDS) - if self._wait_event.wait(self.UPGRADE_ATTEMPT_WAIT_SECONDS): - logger.info('Stopping upgrade attempts due to shutdown') - return - try: logger.info('Attempting to perform upgrade') self._attempt_upgrade() @@ -489,6 +483,12 @@ class ForceUpgrader(): # Assume all other errors are temporary logger.exception('Unknown exception: %s', exception) + logger.info('Waiting for %s seconds before attempting upgrade', + self.UPGRADE_ATTEMPT_WAIT_SECONDS) + if self._wait_event.wait(self.UPGRADE_ATTEMPT_WAIT_SECONDS): + logger.info('Stopping upgrade attempts due to shutdown') + return + logger.info('Giving up on upgrade after too many retries') def shutdown(self): @@ -748,14 +748,6 @@ class DpkgHandler: This method is guaranteed to not to run more than once simultaneously. """ for _ in range(self.HANDLE_ATTEMPTS): - logger.info( - 'Waiting for %s seconds before attempting post-dpkg ' - 'operations', self.HANDLE_ATTEMPT_WAIT_SECONDS) - if self._wait_event.wait(self.HANDLE_ATTEMPT_WAIT_SECONDS): - logger.info( - 'Stopping post-dpkg operation attempts due to shutdown') - return - try: logger.info('Attempting to perform post-dpkg operations') self._attempt_post_invoke() @@ -771,6 +763,14 @@ class DpkgHandler: # Assume all other errors are temporary logger.exception('Unknown exception: %s', exception) + logger.info( + 'Waiting for %s seconds before attempting post-dpkg ' + 'operations', self.HANDLE_ATTEMPT_WAIT_SECONDS) + if self._wait_event.wait(self.HANDLE_ATTEMPT_WAIT_SECONDS): + logger.info( + 'Stopping post-dpkg operation attempts due to shutdown') + return + logger.info('Giving up on post-dpkg operations after too many retries') def _attempt_post_invoke(self) -> None: