refactor: Move unit list to ChatmailVenvDeployer

- Split _configure_remote_venv_with_chatmaild() into two functions.
  _configure_remote_venv_with_chatmaild() handles details specific to
  the "venv", while the new _configure_remote_units() is a more
  general function that is applicable to several services.
- Renamed _activate_remote_venv_with_chatmaild() to
  _activate_remote_units() because doesn't have anything
  venv-specific.
- Removed list of units from helper functions (where it appeared
  twice); moved it to ChatmailVenvDeployer, where its is passed as an
  argument to _configure_remote_units() and _activate_remote_units().
This commit is contained in:
cliffmccarthy
2025-11-04 15:57:34 -06:00
parent 1aa4896260
commit 38ba28be8a

View File

@@ -129,26 +129,21 @@ def _configure_remote_venv_with_chatmaild(config) -> None:
}, },
) )
def _configure_remote_units(mail_domain, units) -> None:
remote_base_dir = "/usr/local/lib/chatmaild"
remote_venv_dir = f"{remote_base_dir}/venv"
remote_chatmail_inipath = f"{remote_base_dir}/chatmail.ini"
root_owned = dict(user="root", group="root", mode="644")
# install systemd units # install systemd units
for fn in ( for fn in units:
"doveauth",
"filtermail",
"filtermail-incoming",
"echobot",
"chatmail-metadata",
"lastlogin",
"turnserver",
"chatmail-expire",
"chatmail-expire.timer",
"chatmail-fsreport",
"chatmail-fsreport.timer",
):
execpath = fn if fn != "filtermail-incoming" else "filtermail" execpath = fn if fn != "filtermail-incoming" else "filtermail"
params = dict( params = dict(
execpath=f"{remote_venv_dir}/bin/{execpath}", execpath=f"{remote_venv_dir}/bin/{execpath}",
config_path=remote_chatmail_inipath, config_path=remote_chatmail_inipath,
remote_venv_dir=remote_venv_dir, remote_venv_dir=remote_venv_dir,
mail_domain=config.mail_domain, mail_domain=mail_domain,
) )
basename = fn if "." in fn else f"{fn}.service" basename = fn if "." in fn else f"{fn}.service"
@@ -164,21 +159,9 @@ def _configure_remote_venv_with_chatmaild(config) -> None:
) )
def _activate_remote_venv_with_chatmaild() -> None: def _activate_remote_units(units) -> None:
# activate systemd units # activate systemd units
for fn in ( for fn in units:
"doveauth",
"filtermail",
"filtermail-incoming",
"echobot",
"chatmail-metadata",
"lastlogin",
"turnserver",
"chatmail-expire",
"chatmail-expire.timer",
"chatmail-fsreport",
"chatmail-fsreport.timer",
):
basename = fn if "." in fn else f"{fn}.service" basename = fn if "." in fn else f"{fn}.service"
if fn == "chatmail-expire" or fn == "chatmail-fsreport": if fn == "chatmail-expire" or fn == "chatmail-fsreport":
@@ -1028,6 +1011,19 @@ class ChatmailVenvDeployer(Deployer):
def __init__(self, *, config, **kwargs): def __init__(self, *, config, **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
self.config = config self.config = config
self.units = (
"doveauth",
"filtermail",
"filtermail-incoming",
"echobot",
"chatmail-metadata",
"lastlogin",
"turnserver",
"chatmail-expire",
"chatmail-expire.timer",
"chatmail-fsreport",
"chatmail-fsreport.timer",
)
@staticmethod @staticmethod
def install_impl(): def install_impl():
@@ -1035,9 +1031,10 @@ class ChatmailVenvDeployer(Deployer):
def configure_impl(self): def configure_impl(self):
_configure_remote_venv_with_chatmaild(self.config) _configure_remote_venv_with_chatmaild(self.config)
_configure_remote_units(self.config.mail_domain, self.units)
def activate_impl(self): def activate_impl(self):
_activate_remote_venv_with_chatmaild() _activate_remote_units(self.units)
class ChatmailDeployer(Deployer): class ChatmailDeployer(Deployer):