From 0e756c653df266b3529b25fd01138db736f96c4e Mon Sep 17 00:00:00 2001 From: cliffmccarthy <16453869+cliffmccarthy@users.noreply.github.com> Date: Wed, 8 Oct 2025 23:28:05 -0500 Subject: [PATCH] refactor: Add EchobotDeployer - This class is a special case because it has a dependency on the Postfix and Dovecot deployers. When deciding whether to restart the echobot service, it needs to know whether the Postfix and Dovecot deployers restarted their services. To support this dependency, the PostfixDeployer and DovecotDeployer objects are passed to the EchobotDeployer object, so it can check their was_restarted attributes. --- cmdeploy/src/cmdeploy/__init__.py | 46 +++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/cmdeploy/src/cmdeploy/__init__.py b/cmdeploy/src/cmdeploy/__init__.py index 5a4e5aa2..d1b99360 100644 --- a/cmdeploy/src/cmdeploy/__init__.py +++ b/cmdeploy/src/cmdeploy/__init__.py @@ -934,6 +934,33 @@ class JournaldDeployer(Deployer): self.need_restart = False +class EchobotDeployer(Deployer): + # + # This deployer depends on the dovecot and postfix deployers because + # it needs to base its decision of whether to restart the service on + # whether those two services were restarted. + # + def __init__(self, *, dovecot_deployer, postfix_deployer, **kwargs): + super().__init__(**kwargs) + self.dovecot_deployer = dovecot_deployer + self.postfix_deployer = postfix_deployer + + @staticmethod + def install_impl(): + apt.packages( + # required for setfacl for echobot + name="Install acl", + packages="acl", + ) + + def activate_impl(self): + systemd.service( + name="Restart echobot if postfix and dovecot were just started", + service="echobot.service", + restarted=self.postfix_deployer.was_restarted and self.dovecot_deployer.was_restarted, + ) + + class ChatmailVenvDeployer(Deployer): def __init__(self, *, config, **kwargs): super().__init__(**kwargs) @@ -1064,6 +1091,9 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None: nginx_deployer = NginxDeployer(config=config) rspamd_deployer = RspamdDeployer() fcgiwrap_deployer = FcgiwrapDeployer() + echobot_deployer = EchobotDeployer( + dovecot_deployer=dovecot_deployer, postfix_deployer=postfix_deployer + ) journald_deployer = JournaldDeployer() mtail_deployer = MtailDeployer(mtail_address=config.mtail_address) @@ -1080,6 +1110,7 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None: nginx_deployer, rspamd_deployer, fcgiwrap_deployer, + echobot_deployer, journald_deployer, mtail_deployer, ] @@ -1136,12 +1167,7 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None: acmetool_deployer.configure() acmetool_deployer.activate() - apt.packages( - # required for setfacl for echobot - name="Install acl", - packages="acl", - ) - + echobot_deployer.install() mtasts_deployer.install() opendkim_deployer.install() postfix_deployer.install() @@ -1178,18 +1204,14 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None: fcgiwrap_deployer.configure() opendkim_deployer.configure() opendkim_deployer.activate() + echobot_deployer.configure() dovecot_deployer.activate() postfix_deployer.activate() nginx_deployer.activate() rspamd_deployer.activate() fcgiwrap_deployer.activate() - - systemd.service( - name="Restart echobot if postfix and dovecot were just started", - service="echobot.service", - restarted=postfix_deployer.was_restarted and dovecot_deployer.was_restarted, - ) + echobot_deployer.activate() chatmail_deployer.configure() chatmail_deployer.activate()