From a349fc0334d7c40a35dfc9dc7ecc8723e5fc8edd Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sat, 29 Jun 2024 20:04:19 +0200 Subject: [PATCH] apps: tweaks to be more robust and prevent the stupid flood of 'sh: 0: getcwd() failed: No such file or directory' when running an app upgrade/remove from /var/www/$app, sometimes making it look like the upgrade failed when it didnt --- src/service.py | 6 ++++-- src/utils/system.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/service.py b/src/service.py index 5e49dfc8a..977b9a902 100644 --- a/src/service.py +++ b/src/service.py @@ -688,13 +688,15 @@ def _get_services(): ] for name in services_with_package_condition: package = services[name]["ignore_if_package_is_not_installed"] - if os.system(f"dpkg --list | grep -q 'ii *{package}'") != 0: + if check_output(f"dpkg-query --show --showformat='${{db:Status-Status}}' '{package}' 2>/dev/null || true") != "installed": del services[name] php_fpm_versions = check_output( - r"dpkg --list | grep -P 'ii php\d.\d-fpm' | awk '{print $2}' | grep -o -P '\d.\d' || true" + r"dpkg --list | grep -P 'ii php\d.\d-fpm' | awk '{print $2}' | grep -o -P '\d.\d' || true", + cwd="/tmp" ) php_fpm_versions = [v for v in php_fpm_versions.split("\n") if v.strip()] + for version in php_fpm_versions: # Skip php 7.3 which is most likely dead after buster->bullseye migration # because users get spooked diff --git a/src/utils/system.py b/src/utils/system.py index 27ef98dd1..5bea7f971 100644 --- a/src/utils/system.py +++ b/src/utils/system.py @@ -159,7 +159,7 @@ def ynh_packages_version(*args, **kwargs): def dpkg_is_broken(): - if check_output("dpkg --audit") != "": + if check_output("dpkg --audit", cwd="/tmp/") != "": return True # If dpkg is broken, /var/lib/dpkg/updates # will contains files like 0001, 0002, ...