refactor: Add MtailDeployer

- This splits the existing deploy_mtail() routine into methods for the
  install, configure, and activate stages.
This commit is contained in:
cliffmccarthy
2025-09-08 08:39:59 -05:00
parent 84ab4bb6b8
commit d1788b7c65

View File

@@ -747,7 +747,13 @@ def deploy_turn_server(config):
) )
def deploy_mtail(config): class MtailDeployer(Deployer):
def __init__(self, *, mtail_address, **kwargs):
super().__init__(**kwargs)
self.mtail_address = mtail_address
@staticmethod
def install_impl():
# Uninstall mtail package, we are going to install a static binary. # Uninstall mtail package, we are going to install a static binary.
apt.packages(name="Uninstall mtail", packages=["mtail"], present=False) apt.packages(name="Uninstall mtail", packages=["mtail"], present=False)
@@ -770,15 +776,18 @@ def deploy_mtail(config):
], ],
) )
def configure_impl(self):
# Using our own systemd unit instead of `/usr/lib/systemd/system/mtail.service`. # Using our own systemd unit instead of `/usr/lib/systemd/system/mtail.service`.
# This allows to read from journalctl instead of log files. # This allows to read from journalctl instead of log files.
files.template( files.template(
src=importlib.resources.files(__package__).joinpath("mtail/mtail.service.j2"), src=importlib.resources.files(__package__).joinpath(
"mtail/mtail.service.j2"
),
dest="/etc/systemd/system/mtail.service", dest="/etc/systemd/system/mtail.service",
user="root", user="root",
group="root", group="root",
mode="644", mode="644",
address=config.mtail_address or "127.0.0.1", address=self.mtail_address or "127.0.0.1",
port=3903, port=3903,
) )
@@ -792,14 +801,17 @@ def deploy_mtail(config):
group="root", group="root",
mode="644", mode="644",
) )
self.need_restart = mtail_conf.changed
def activate_impl(self):
systemd.service( systemd.service(
name="Start and enable mtail", name="Start and enable mtail",
service="mtail.service", service="mtail.service",
running=bool(config.mtail_address), running=bool(self.mtail_address),
enabled=bool(config.mtail_address), enabled=bool(self.mtail_address),
restarted=mtail_conf.changed, restarted=self.need_restart,
) )
self.need_restart = False
class IrohDeployer(Deployer): class IrohDeployer(Deployer):
@@ -931,6 +943,7 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None:
nginx_deployer = NginxDeployer(config=config) nginx_deployer = NginxDeployer(config=config)
journald_deployer = JournaldDeployer() journald_deployer = JournaldDeployer()
mtail_deployer = MtailDeployer(mtail_address=config.mtail_address)
all_deployers = [ all_deployers = [
unbound_deployer, unbound_deployer,
@@ -941,6 +954,7 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None:
postfix_deployer, postfix_deployer,
nginx_deployer, nginx_deployer,
journald_deployer, journald_deployer,
mtail_deployer,
] ]
# #
@@ -1116,4 +1130,6 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None:
mode="700", mode="700",
) )
deploy_mtail(config) mtail_deployer.install()
mtail_deployer.configure()
mtail_deployer.activate()