Skip to content

Commit a298dcb

Browse files
committed
shift mtail deployer to subdir
1 parent 51056c2 commit a298dcb

File tree

2 files changed

+69
-61
lines changed

2 files changed

+69
-61
lines changed

cmdeploy/src/cmdeploy/deployers.py

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
get_resource,
2727
)
2828
from .dovecot.deployer import DovecotDeployer
29+
from .mtail.deployer import MtailDeployer
2930
from .nginx.deployer import NginxDeployer
3031
from .opendkim.deployer import OpendkimDeployer
3132
from .postfix.deployer import PostfixDeployer
@@ -320,67 +321,6 @@ def activate(self):
320321
_activate_remote_units(self.units)
321322

322323

323-
class MtailDeployer(Deployer):
324-
def __init__(self, mtail_address):
325-
self.mtail_address = mtail_address
326-
327-
def install(self):
328-
# Uninstall mtail package to install a static binary.
329-
apt.packages(name="Uninstall mtail", packages=["mtail"], present=False)
330-
331-
(url, sha256sum) = {
332-
"x86_64": (
333-
"https://github.com/google/mtail/releases/download/v3.0.8/mtail_3.0.8_linux_amd64.tar.gz",
334-
"123c2ee5f48c3eff12ebccee38befd2233d715da736000ccde49e3d5607724e4",
335-
),
336-
"aarch64": (
337-
"https://github.com/google/mtail/releases/download/v3.0.8/mtail_3.0.8_linux_arm64.tar.gz",
338-
"aa04811c0929b6754408676de520e050c45dddeb3401881888a092c9aea89cae",
339-
),
340-
}[host.get_fact(facts.server.Arch)]
341-
342-
server.shell(
343-
name="Download mtail",
344-
commands=[
345-
f"(echo '{sha256sum} /usr/local/bin/mtail' | sha256sum -c) || (curl -L {url} | gunzip | tar -x -f - mtail -O >/usr/local/bin/mtail.new && mv /usr/local/bin/mtail.new /usr/local/bin/mtail)",
346-
"chmod 755 /usr/local/bin/mtail",
347-
],
348-
)
349-
350-
def configure(self):
351-
# Using our own systemd unit instead of `/usr/lib/systemd/system/mtail.service`.
352-
# This allows to read from journalctl instead of log files.
353-
files.template(
354-
src=get_resource("mtail/mtail.service.j2"),
355-
dest="/etc/systemd/system/mtail.service",
356-
user="root",
357-
group="root",
358-
mode="644",
359-
address=self.mtail_address or "127.0.0.1",
360-
port=3903,
361-
)
362-
363-
mtail_conf = files.put(
364-
name="Mtail configuration",
365-
src=get_resource("mtail/delivered_mail.mtail"),
366-
dest="/etc/mtail/delivered_mail.mtail",
367-
user="root",
368-
group="root",
369-
mode="644",
370-
)
371-
self.need_restart = mtail_conf.changed
372-
373-
def activate(self):
374-
systemd.service(
375-
name="Start and enable mtail",
376-
service="mtail.service",
377-
running=bool(self.mtail_address),
378-
enabled=bool(self.mtail_address),
379-
restarted=self.need_restart,
380-
)
381-
self.need_restart = False
382-
383-
384324
class IrohDeployer(Deployer):
385325
def __init__(self, enable_iroh_relay):
386326
self.enable_iroh_relay = enable_iroh_relay
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
from pyinfra import facts, host
2+
from pyinfra.operations import apt, files, server, systemd
3+
4+
from cmdeploy.basedeploy import (
5+
Deployer,
6+
get_resource,
7+
)
8+
9+
10+
class MtailDeployer(Deployer):
11+
def __init__(self, mtail_address):
12+
self.mtail_address = mtail_address
13+
14+
def install(self):
15+
# Uninstall mtail package to install a static binary.
16+
apt.packages(name="Uninstall mtail", packages=["mtail"], present=False)
17+
18+
(url, sha256sum) = {
19+
"x86_64": (
20+
"https://github.com/google/mtail/releases/download/v3.0.8/mtail_3.0.8_linux_amd64.tar.gz",
21+
"123c2ee5f48c3eff12ebccee38befd2233d715da736000ccde49e3d5607724e4",
22+
),
23+
"aarch64": (
24+
"https://github.com/google/mtail/releases/download/v3.0.8/mtail_3.0.8_linux_arm64.tar.gz",
25+
"aa04811c0929b6754408676de520e050c45dddeb3401881888a092c9aea89cae",
26+
),
27+
}[host.get_fact(facts.server.Arch)]
28+
29+
server.shell(
30+
name="Download mtail",
31+
commands=[
32+
f"(echo '{sha256sum} /usr/local/bin/mtail' | sha256sum -c) || (curl -L {url} | gunzip | tar -x -f - mtail -O >/usr/local/bin/mtail.new && mv /usr/local/bin/mtail.new /usr/local/bin/mtail)",
33+
"chmod 755 /usr/local/bin/mtail",
34+
],
35+
)
36+
37+
def configure(self):
38+
# Using our own systemd unit instead of `/usr/lib/systemd/system/mtail.service`.
39+
# This allows to read from journalctl instead of log files.
40+
files.template(
41+
src=get_resource("mtail/mtail.service.j2"),
42+
dest="/etc/systemd/system/mtail.service",
43+
user="root",
44+
group="root",
45+
mode="644",
46+
address=self.mtail_address or "127.0.0.1",
47+
port=3903,
48+
)
49+
50+
mtail_conf = files.put(
51+
name="Mtail configuration",
52+
src=get_resource("mtail/delivered_mail.mtail"),
53+
dest="/etc/mtail/delivered_mail.mtail",
54+
user="root",
55+
group="root",
56+
mode="644",
57+
)
58+
self.need_restart = mtail_conf.changed
59+
60+
def activate(self):
61+
systemd.service(
62+
name="Start and enable mtail",
63+
service="mtail.service",
64+
running=bool(self.mtail_address),
65+
enabled=bool(self.mtail_address),
66+
restarted=self.need_restart,
67+
)
68+
self.need_restart = False

0 commit comments

Comments
 (0)