From e1b0741e533116ecfc961e1bf27b90be17f8b706 Mon Sep 17 00:00:00 2001 From: Mikhail Sandakov Date: Tue, 24 Sep 2024 16:34:20 +0300 Subject: [PATCH] Move Mailman systemd service operations to a separate action We will now skip any interactions with the Mailman service if it is not actoive at the start of the conversion. By default, mailman is not configured and the service will fail to start. Therefore, attempts to start it during the revert or finishing stage will also fail. --- pleskdistup/actions/systemd.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/pleskdistup/actions/systemd.py b/pleskdistup/actions/systemd.py index a6e53d1..30aeaec 100644 --- a/pleskdistup/actions/systemd.py +++ b/pleskdistup/actions/systemd.py @@ -89,7 +89,6 @@ def __init__(self) -> None: "drwebd.service", "fail2ban.service", "httpd.service", - "mailman.service", "mariadb.service", "named-chroot.service", "plesk-ext-monitoring-hcd.service", @@ -176,6 +175,33 @@ def _revert_action(self) -> action.ActionResult: return action.ActionResult() +# We need to handle the mailman service separately because it is not configured and is stopped by default +# If we try to start an unconfigured service, it will fail, causing issues during the revert and finish stages +class HandleMailmanService(action.ActiveAction): + mailman_service: str + + def __init__(self) -> None: + self.name = "handle mailman service" + self.mailman_service = "mailman.service" + + def _is_required(self) -> bool: + return systemd.is_service_startable(self.mailman_service) and systemd.is_service_active(self.mailman_service) + + def _prepare_action(self) -> action.ActionResult: + util.logged_check_call(["/usr/bin/systemctl", "stop", self.mailman_service]) + util.logged_check_call(["/usr/bin/systemctl", "disable", self.mailman_service]) + return action.ActionResult() + + def _post_action(self) -> action.ActionResult: + util.logged_check_call(["/usr/bin/systemctl", "enable", self.mailman_service]) + return action.ActionResult() + + def _revert_action(self) -> action.ActionResult: + util.logged_check_call(["/usr/bin/systemctl", "enable", self.mailman_service]) + util.logged_check_call(["/usr/bin/systemctl", "start", self.mailman_service]) + return action.ActionResult() + + class StartPleskBasicServices(action.ActiveAction): plesk_basic_services: typing.List[str]