diff --git a/pleskdistup/actions/systemd.py b/pleskdistup/actions/systemd.py index eb930e6..b8df658 100644 --- a/pleskdistup/actions/systemd.py +++ b/pleskdistup/actions/systemd.py @@ -154,7 +154,6 @@ def __init__(self) -> None: self.name = "starting plesk services" self.plesk_basic_services = [ "mariadb.service", - "mysqld.service", "plesk-task-manager.service", "plesk-web-socket.service", "sw-cp-server.service", @@ -162,6 +161,11 @@ def __init__(self) -> None: ] self.plesk_basic_services = [service for service in self.plesk_basic_services if systemd.is_service_exists(service)] + # Once MariaDB has started, systemctl will not be able to control mysqld as a linked unit. + # Therefore, we should manage mysqld separately and only if MariaDB is not present + if "mariadb.service" not in self.plesk_basic_services and systemd.is_service_startable("mysqld.service"): + self.plesk_basic_services.append("mysqld.service") + def _enable_services(self) -> action.ActionResult: # MariaDB could be started before, so we should stop it first # TODO. Or we could check it is started and just remove it from list diff --git a/pleskdistup/common/src/dpkg.py b/pleskdistup/common/src/dpkg.py index 0cd1f36..7dae729 100644 --- a/pleskdistup/common/src/dpkg.py +++ b/pleskdistup/common/src/dpkg.py @@ -191,3 +191,9 @@ def restore_installation() -> None: def do_distupgrade() -> None: util.logged_check_call(["apt-get", "dist-upgrade", "-y"] + APT_CHOOSE_OLD_FILES_OPTIONS, env={"PATH": os.environ["PATH"], "DEBIAN_FRONTEND": "noninteractive"}) + + +def get_installed_packages_list(regex: str) -> typing.List[str]: + res = subprocess.check_output(["/usr/bin/dpkg-query", "-W", "-f", "${binary:Package}\n", regex], + universal_newlines=True) + return res.splitlines() diff --git a/pleskdistup/common/src/mariadb.py b/pleskdistup/common/src/mariadb.py index edc520e..e9b5b07 100644 --- a/pleskdistup/common/src/mariadb.py +++ b/pleskdistup/common/src/mariadb.py @@ -71,7 +71,7 @@ def __init__(self, to_extract: str): def __str__(self): """Return a string representation of a PHPVersion object.""" - return f"PHP {self.major}.{self.minor}.{self.patch}" + return f"{self.major}.{self.minor}.{self.patch}" def __lt__(self, other): return self.major < other.major or (self.major == other.major and self.minor < other.minor) or (self.major == other.major and self.minor == other.minor and self.patch < other.patch) diff --git a/pleskdistup/common/src/packages.py b/pleskdistup/common/src/packages.py index 8fb3709..7c20700 100644 --- a/pleskdistup/common/src/packages.py +++ b/pleskdistup/common/src/packages.py @@ -76,3 +76,13 @@ def autoremove_outdated_packages() -> None: return rpm.autoremove_outdated_packages() else: raise NotImplementedError(f"Unsupported distro {started_on}") + + +def get_installed_packages_list(regex: str) -> typing.List[str]: + started_on = dist.get_distro() + if started_on.deb_based: + return dpkg.get_installed_packages_list(regex) + elif started_on.rhel_based: + return rpm.get_installed_packages_list(regex) + else: + raise NotImplementedError(f"Unsupported distro {started_on}") diff --git a/pleskdistup/common/src/rpm.py b/pleskdistup/common/src/rpm.py index 9eb8874..a66fd54 100644 --- a/pleskdistup/common/src/rpm.py +++ b/pleskdistup/common/src/rpm.py @@ -160,6 +160,11 @@ def install_packages(pkgs: typing.List[str], repository: typing.Optional[str] = util.logged_check_call(command) +def get_installed_packages_list(regex: str) -> typing.List[str]: + res = subprocess.check_output(["/usr/bin/rpm", "-qa", "--queryformat", "%{NAME}\n", regex], universal_newlines=True) + return res.splitlines() + + def remove_packages(pkgs: typing.List[str]) -> None: if len(pkgs) == 0: return