diff --git a/pleskdistup/actions/grub.py b/pleskdistup/actions/grub.py index 3383022..25cf4c1 100644 --- a/pleskdistup/actions/grub.py +++ b/pleskdistup/actions/grub.py @@ -5,6 +5,7 @@ DEBCONF_CMD = "/usr/bin/debconf-show" + class AssertGrubInstallDeviceExists(action.CheckAction): def __init__(self) -> None: self.name = "check GRUB installation device exists" diff --git a/pleskdistup/actions/systemd.py b/pleskdistup/actions/systemd.py index a6e53d1..bd60e22 100644 --- a/pleskdistup/actions/systemd.py +++ b/pleskdistup/actions/systemd.py @@ -83,13 +83,14 @@ class DisablePleskRelatedServicesDuringUpgrade(action.ActiveAction): def __init__(self) -> None: self.name = "disable plesk related services" + # Be cautious when adding the mailman service here. If mailman is not configured, the service will not start. + # The best way to handle mailman is to use the DisableServiceDuringUpgrade action. plesk_known_systemd_services = [ "crond.service", "dovecot.service", "drwebd.service", "fail2ban.service", "httpd.service", - "mailman.service", "mariadb.service", "named-chroot.service", "plesk-ext-monitoring-hcd.service", @@ -176,6 +177,31 @@ def _revert_action(self) -> action.ActionResult: return action.ActionResult() +class DisableServiceDuringUpgrade(action.ActiveAction): + target_service: str + + def __init__(self, target_service: str) -> None: + self.name = f"handle {target_service} service" + self.target_service = target_service + + def _is_required(self) -> bool: + return systemd.is_service_startable(self.target_service) and systemd.is_service_active(self.target_service) + + def _prepare_action(self) -> action.ActionResult: + util.logged_check_call(["/usr/bin/systemctl", "stop", self.target_service]) + util.logged_check_call(["/usr/bin/systemctl", "disable", self.target_service]) + return action.ActionResult() + + def _post_action(self) -> action.ActionResult: + util.logged_check_call(["/usr/bin/systemctl", "enable", self.target_service]) + return action.ActionResult() + + def _revert_action(self) -> action.ActionResult: + util.logged_check_call(["/usr/bin/systemctl", "enable", self.target_service]) + util.logged_check_call(["/usr/bin/systemctl", "start", self.target_service]) + return action.ActionResult() + + class StartPleskBasicServices(action.ActiveAction): plesk_basic_services: typing.List[str]