From 1b89151c38ec04e9ee03d04d3a8de71363695284 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Wed, 5 Mar 2025 12:48:36 -0800 Subject: [PATCH] upgrades: Log apt output to journal during dist upgrade Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/action_utils.py | 6 +++--- plinth/modules/upgrades/distupgrade.py | 14 +++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/plinth/action_utils.py b/plinth/action_utils.py index a1f26a19c..8e275a58a 100644 --- a/plinth/action_utils.py +++ b/plinth/action_utils.py @@ -449,14 +449,14 @@ def is_disk_image(): return os.path.exists('/var/lib/freedombox/is-freedombox-disk-image') -def run_apt_command(arguments): +def run_apt_command(arguments, stdout=subprocess.DEVNULL): """Run apt-get with provided arguments.""" command = ['apt-get', '--assume-yes', '--quiet=2'] + arguments env = os.environ.copy() env['DEBIAN_FRONTEND'] = 'noninteractive' - process = subprocess.run(command, stdin=subprocess.DEVNULL, - stdout=subprocess.DEVNULL, env=env, check=False) + process = subprocess.run(command, stdin=subprocess.DEVNULL, stdout=stdout, + env=env, check=False) return process.returncode diff --git a/plinth/modules/upgrades/distupgrade.py b/plinth/modules/upgrades/distupgrade.py index 494e0c40a..1124e04ec 100644 --- a/plinth/modules/upgrades/distupgrade.py +++ b/plinth/modules/upgrades/distupgrade.py @@ -27,6 +27,11 @@ DIST_UPGRADE_PRE_DEBCONF_SELECTIONS: list[str] = [ ] +def _apt_run(arguments): + """Run an apt command and ensure that output is written to stdout.""" + return action_utils.run_apt_command(arguments, stdout=None) + + def _sources_list_update(old_codename: str, new_codename: str): """Change the distribution in /etc/apt/sources.list.""" logging.info('Upgrading from %s to %s...', old_codename, new_codename) @@ -208,26 +213,25 @@ def _packages_remove_obsolete() -> None: if DIST_UPGRADE_OBSOLETE_PACKAGES: print(f'Removing packages: {DIST_UPGRADE_OBSOLETE_PACKAGES}...', flush=True) - action_utils.run_apt_command(['remove'] + - DIST_UPGRADE_OBSOLETE_PACKAGES) + _apt_run(['remove'] + DIST_UPGRADE_OBSOLETE_PACKAGES) def _apt_update(): """Run 'apt update'.""" print('Updating Apt cache...', flush=True) - action_utils.run_apt_command(['update']) + _apt_run(['update']) def _apt_autoremove(): """Run 'apt autoremove'.""" print('Running apt autoremove...', flush=True) - action_utils.run_apt_command(['autoremove']) + _apt_run(['autoremove']) def _apt_full_upgrade(): """Run and check if apt upgrade was successful.""" print('Running apt full-upgrade...', flush=True) - returncode = action_utils.run_apt_command(['full-upgrade']) + returncode = _apt_run(['full-upgrade']) if returncode: raise RuntimeError( 'Apt full-upgrade was not successful. Distribution upgrade '