refactor: Add TurnDeployer

- This splits the existing deploy_turn_server() routine into methods
  for the install, configure, and activate stages.
This commit is contained in:
cliffmccarthy
2025-10-11 11:23:43 -05:00
parent 68b78bf6d2
commit 741948682f

View File

@@ -756,7 +756,14 @@ def check_config(config):
return config return config
def deploy_turn_server(config): class TurnDeployer(Deployer):
def __init__(self, *, mail_domain, **kwargs):
super().__init__(**kwargs)
self.mail_domain = mail_domain
self.daemon_reload = False
@staticmethod
def install_impl():
(url, sha256sum) = { (url, sha256sum) = {
"x86_64": ( "x86_64": (
"https://github.com/chatmail/chatmail-turn/releases/download/v0.3/chatmail-turn-x86_64-linux", "https://github.com/chatmail/chatmail-turn/releases/download/v0.3/chatmail-turn-x86_64-linux",
@@ -768,8 +775,6 @@ def deploy_turn_server(config):
), ),
}[host.get_fact(facts.server.Arch)] }[host.get_fact(facts.server.Arch)]
need_restart = False
existing_sha256sum = host.get_fact(Sha256File, "/usr/local/bin/chatmail-turn") existing_sha256sum = host.get_fact(Sha256File, "/usr/local/bin/chatmail-turn")
if existing_sha256sum != sha256sum: if existing_sha256sum != sha256sum:
server.shell( server.shell(
@@ -779,12 +784,18 @@ def deploy_turn_server(config):
"chmod 755 /usr/local/bin/chatmail-turn", "chmod 755 /usr/local/bin/chatmail-turn",
], ],
) )
need_restart = True
#
# This will set need_restart when called from an object's
# install() method.
#
return True
def configure_impl(self):
source_path = importlib.resources.files(__package__).joinpath( source_path = importlib.resources.files(__package__).joinpath(
"service", "turnserver.service.f" "service", "turnserver.service.f"
) )
content = source_path.read_text().format(mail_domain=config.mail_domain).encode() content = source_path.read_text().format(mail_domain=self.mail_domain).encode()
systemd_unit = files.put( systemd_unit = files.put(
name="Upload turnserver.service", name="Upload turnserver.service",
@@ -794,16 +805,20 @@ def deploy_turn_server(config):
group="root", group="root",
mode="644", mode="644",
) )
need_restart |= systemd_unit.changed self.daemon_reload = systemd_unit.changed
self.need_restart |= systemd_unit.changed
def activate_impl(self):
systemd.service( systemd.service(
name="Setup turnserver service", name="Setup turnserver service",
service="turnserver.service", service="turnserver.service",
running=True, running=True,
enabled=True, enabled=True,
restarted=need_restart, restarted=self.need_restart,
daemon_reload=systemd_unit.changed, daemon_reload=self.daemon_reload,
) )
self.daemon_reload = False
self.need_restart = False
class MtailDeployer(Deployer): class MtailDeployer(Deployer):
@@ -1105,6 +1120,7 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None:
tls_domains = [mail_domain, f"mta-sts.{mail_domain}", f"www.{mail_domain}"] tls_domains = [mail_domain, f"mta-sts.{mail_domain}", f"www.{mail_domain}"]
chatmail_deployer = ChatmailDeployer(mail_domain=mail_domain) chatmail_deployer = ChatmailDeployer(mail_domain=mail_domain)
turn_deployer = TurnDeployer(mail_domain=mail_domain)
unbound_deployer = UnboundDeployer() unbound_deployer = UnboundDeployer()
iroh_deployer = IrohDeployer(enable_iroh_relay=config.enable_iroh_relay) iroh_deployer = IrohDeployer(enable_iroh_relay=config.enable_iroh_relay)
@@ -1133,6 +1149,7 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None:
all_deployers = [ all_deployers = [
chatmail_deployer, chatmail_deployer,
turn_deployer,
unbound_deployer, unbound_deployer,
iroh_deployer, iroh_deployer,
acmetool_deployer, acmetool_deployer,
@@ -1162,7 +1179,9 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None:
chatmail_deployer.install() chatmail_deployer.install()
deploy_turn_server(config) turn_deployer.install()
turn_deployer.configure()
turn_deployer.activate()
port_services = [ port_services = [
(["master", "smtpd"], 25), (["master", "smtpd"], 25),