mirror of
https://github.com/chatmail/relay.git
synced 2026-05-21 13:28:05 +00:00
refactor: Add MtailDeployer
- This splits the existing deploy_mtail() routine into methods for the install, configure, and activate stages.
This commit is contained in:
@@ -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.
|
||||
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`.
|
||||
# This allows to read from journalctl instead of log files.
|
||||
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",
|
||||
user="root",
|
||||
group="root",
|
||||
mode="644",
|
||||
address=config.mtail_address or "127.0.0.1",
|
||||
address=self.mtail_address or "127.0.0.1",
|
||||
port=3903,
|
||||
)
|
||||
|
||||
@@ -792,14 +801,17 @@ def deploy_mtail(config):
|
||||
group="root",
|
||||
mode="644",
|
||||
)
|
||||
self.need_restart = mtail_conf.changed
|
||||
|
||||
def activate_impl(self):
|
||||
systemd.service(
|
||||
name="Start and enable mtail",
|
||||
service="mtail.service",
|
||||
running=bool(config.mtail_address),
|
||||
enabled=bool(config.mtail_address),
|
||||
restarted=mtail_conf.changed,
|
||||
running=bool(self.mtail_address),
|
||||
enabled=bool(self.mtail_address),
|
||||
restarted=self.need_restart,
|
||||
)
|
||||
self.need_restart = False
|
||||
|
||||
|
||||
class IrohDeployer(Deployer):
|
||||
@@ -931,6 +943,7 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None:
|
||||
|
||||
nginx_deployer = NginxDeployer(config=config)
|
||||
journald_deployer = JournaldDeployer()
|
||||
mtail_deployer = MtailDeployer(mtail_address=config.mtail_address)
|
||||
|
||||
all_deployers = [
|
||||
unbound_deployer,
|
||||
@@ -941,6 +954,7 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None:
|
||||
postfix_deployer,
|
||||
nginx_deployer,
|
||||
journald_deployer,
|
||||
mtail_deployer,
|
||||
]
|
||||
|
||||
#
|
||||
@@ -1116,4 +1130,6 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None:
|
||||
mode="700",
|
||||
)
|
||||
|
||||
deploy_mtail(config)
|
||||
mtail_deployer.install()
|
||||
mtail_deployer.configure()
|
||||
mtail_deployer.activate()
|
||||
|
||||
Reference in New Issue
Block a user