refactor: Move echobot out of ChatmailVenvDeployer

- Revised EchobotDeployer to use _configure_remote_units() and
  _activate_remote_units().  The 'activate' stage of
  ChatmailVenvDeployer was unconditionally restarting the service
  every time, so EchobotDeployer no longer needs to depend on the
  was_restarted attributes of the postfix and dovecot deployers in an
  attempt to avoid restarting it; we can just handle the unconditional
  restart in EchobotDeployer.activate_impl().
- Removed echobot from the unit list in ChatmailVenvDeployer.
- Removed now-unused was_restarted attribute from PostfixDeployer and
  DovecotDeployer.
This commit is contained in:
cliffmccarthy
2025-11-04 16:17:19 -06:00
parent b39c27c5cc
commit 9945402d4c

View File

@@ -429,7 +429,6 @@ class PostfixDeployer(Deployer):
super().__init__(**kwargs) super().__init__(**kwargs)
self.config = config self.config = config
self.disable_mail = disable_mail self.disable_mail = disable_mail
self.was_restarted = False
@staticmethod @staticmethod
def required_users(): def required_users():
@@ -457,7 +456,6 @@ class PostfixDeployer(Deployer):
enabled=False if self.disable_mail else True, enabled=False if self.disable_mail else True,
restarted=restart, restarted=restart,
) )
self.was_restarted = restart
self.need_restart = False self.need_restart = False
@@ -566,7 +564,6 @@ class DovecotDeployer(Deployer):
super().__init__(**kwargs) super().__init__(**kwargs)
self.config = config self.config = config
self.disable_mail = disable_mail self.disable_mail = disable_mail
self.was_restarted = False
@staticmethod @staticmethod
def install_impl(): def install_impl():
@@ -589,7 +586,6 @@ class DovecotDeployer(Deployer):
enabled=False if self.disable_mail else True, enabled=False if self.disable_mail else True,
restarted=restart, restarted=restart,
) )
self.was_restarted = restart
self.need_restart = False self.need_restart = False
@@ -957,10 +953,10 @@ class EchobotDeployer(Deployer):
# it needs to base its decision of whether to restart the service on # it needs to base its decision of whether to restart the service on
# whether those two services were restarted. # whether those two services were restarted.
# #
def __init__(self, *, dovecot_deployer, postfix_deployer, **kwargs): def __init__(self, *, mail_domain, **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
self.dovecot_deployer = dovecot_deployer self.mail_domain = mail_domain
self.postfix_deployer = postfix_deployer self.units = ["echobot"]
@staticmethod @staticmethod
def install_impl(): def install_impl():
@@ -970,12 +966,11 @@ class EchobotDeployer(Deployer):
packages="acl", packages="acl",
) )
def configure_impl(self):
_configure_remote_units(self.mail_domain, self.units)
def activate_impl(self): def activate_impl(self):
systemd.service( _activate_remote_units(self.units)
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): class ChatmailVenvDeployer(Deployer):
@@ -986,7 +981,6 @@ class ChatmailVenvDeployer(Deployer):
"doveauth", "doveauth",
"filtermail", "filtermail",
"filtermail-incoming", "filtermail-incoming",
"echobot",
"chatmail-metadata", "chatmail-metadata",
"lastlogin", "lastlogin",
"chatmail-expire", "chatmail-expire",
@@ -1146,9 +1140,7 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None:
fcgiwrap_deployer = FcgiwrapDeployer() fcgiwrap_deployer = FcgiwrapDeployer()
nginx_deployer = NginxDeployer(config=config) nginx_deployer = NginxDeployer(config=config)
rspamd_deployer = RspamdDeployer() rspamd_deployer = RspamdDeployer()
echobot_deployer = EchobotDeployer( echobot_deployer = EchobotDeployer(mail_domain=mail_domain)
dovecot_deployer=dovecot_deployer, postfix_deployer=postfix_deployer
)
mtail_deployer = MtailDeployer(mtail_address=config.mtail_address) mtail_deployer = MtailDeployer(mtail_address=config.mtail_address)
all_deployers = [ all_deployers = [