mirror of
https://github.com/chatmail/relay.git
synced 2026-05-19 04:18:09 +00:00
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:
@@ -756,54 +756,69 @@ def check_config(config):
|
|||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
def deploy_turn_server(config):
|
class TurnDeployer(Deployer):
|
||||||
(url, sha256sum) = {
|
def __init__(self, *, mail_domain, **kwargs):
|
||||||
"x86_64": (
|
super().__init__(**kwargs)
|
||||||
"https://github.com/chatmail/chatmail-turn/releases/download/v0.3/chatmail-turn-x86_64-linux",
|
self.mail_domain = mail_domain
|
||||||
"841e527c15fdc2940b0469e206188ea8f0af48533be12ecb8098520f813d41e4",
|
self.daemon_reload = False
|
||||||
),
|
|
||||||
"aarch64": (
|
|
||||||
"https://github.com/chatmail/chatmail-turn/releases/download/v0.3/chatmail-turn-aarch64-linux",
|
|
||||||
"a5fc2d06d937b56a34e098d2cd72a82d3e89967518d159bf246dc69b65e81b42",
|
|
||||||
),
|
|
||||||
}[host.get_fact(facts.server.Arch)]
|
|
||||||
|
|
||||||
need_restart = False
|
@staticmethod
|
||||||
|
def install_impl():
|
||||||
|
(url, sha256sum) = {
|
||||||
|
"x86_64": (
|
||||||
|
"https://github.com/chatmail/chatmail-turn/releases/download/v0.3/chatmail-turn-x86_64-linux",
|
||||||
|
"841e527c15fdc2940b0469e206188ea8f0af48533be12ecb8098520f813d41e4",
|
||||||
|
),
|
||||||
|
"aarch64": (
|
||||||
|
"https://github.com/chatmail/chatmail-turn/releases/download/v0.3/chatmail-turn-aarch64-linux",
|
||||||
|
"a5fc2d06d937b56a34e098d2cd72a82d3e89967518d159bf246dc69b65e81b42",
|
||||||
|
),
|
||||||
|
}[host.get_fact(facts.server.Arch)]
|
||||||
|
|
||||||
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(
|
||||||
name="Download chatmail-turn",
|
name="Download chatmail-turn",
|
||||||
commands=[
|
commands=[
|
||||||
f"(curl -L {url} >/usr/local/bin/chatmail-turn.new && (echo '{sha256sum} /usr/local/bin/chatmail-turn.new' | sha256sum -c) && mv /usr/local/bin/chatmail-turn.new /usr/local/bin/chatmail-turn)",
|
f"(curl -L {url} >/usr/local/bin/chatmail-turn.new && (echo '{sha256sum} /usr/local/bin/chatmail-turn.new' | sha256sum -c) && mv /usr/local/bin/chatmail-turn.new /usr/local/bin/chatmail-turn)",
|
||||||
"chmod 755 /usr/local/bin/chatmail-turn",
|
"chmod 755 /usr/local/bin/chatmail-turn",
|
||||||
],
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
#
|
||||||
|
# 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(
|
||||||
|
"service", "turnserver.service.f"
|
||||||
)
|
)
|
||||||
need_restart = True
|
content = source_path.read_text().format(mail_domain=self.mail_domain).encode()
|
||||||
|
|
||||||
source_path = importlib.resources.files(__package__).joinpath(
|
systemd_unit = files.put(
|
||||||
"service", "turnserver.service.f"
|
name="Upload turnserver.service",
|
||||||
)
|
src=io.BytesIO(content),
|
||||||
content = source_path.read_text().format(mail_domain=config.mail_domain).encode()
|
dest="/etc/systemd/system/turnserver.service",
|
||||||
|
user="root",
|
||||||
|
group="root",
|
||||||
|
mode="644",
|
||||||
|
)
|
||||||
|
self.daemon_reload = systemd_unit.changed
|
||||||
|
self.need_restart |= systemd_unit.changed
|
||||||
|
|
||||||
systemd_unit = files.put(
|
def activate_impl(self):
|
||||||
name="Upload turnserver.service",
|
systemd.service(
|
||||||
src=io.BytesIO(content),
|
name="Setup turnserver service",
|
||||||
dest="/etc/systemd/system/turnserver.service",
|
service="turnserver.service",
|
||||||
user="root",
|
running=True,
|
||||||
group="root",
|
enabled=True,
|
||||||
mode="644",
|
restarted=self.need_restart,
|
||||||
)
|
daemon_reload=self.daemon_reload,
|
||||||
need_restart |= systemd_unit.changed
|
)
|
||||||
|
self.daemon_reload = False
|
||||||
systemd.service(
|
self.need_restart = False
|
||||||
name="Setup turnserver service",
|
|
||||||
service="turnserver.service",
|
|
||||||
running=True,
|
|
||||||
enabled=True,
|
|
||||||
restarted=need_restart,
|
|
||||||
daemon_reload=systemd_unit.changed,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
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),
|
||||||
|
|||||||
Reference in New Issue
Block a user