fix(mtail): correct boot ordering and deploy restart logic

Correct the systemd unit modifications in 98bc1503 that lead to startup
failures in some instances. Switch to After+Wants = network-online.target
and add RestartSec=2s to give late-binding more interfaces time to appear.

In the deployer, capture the files.template() return value and
appropriately set need_restart and daemon_reload.
This commit is contained in:
j4n
2026-05-04 15:00:16 +02:00
parent b05e26819f
commit fb64be97b5
2 changed files with 7 additions and 3 deletions

View File

@@ -37,7 +37,7 @@ class MtailDeployer(Deployer):
def configure(self): def configure(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( unit = files.template(
src=get_resource("mtail/mtail.service.j2"), src=get_resource("mtail/mtail.service.j2"),
dest="/etc/systemd/system/mtail.service", dest="/etc/systemd/system/mtail.service",
user="root", user="root",
@@ -55,7 +55,8 @@ class MtailDeployer(Deployer):
group="root", group="root",
mode="644", mode="644",
) )
self.need_restart = mtail_conf.changed self.unit_changed = unit.changed
self.need_restart = unit.changed or mtail_conf.changed
def activate(self): def activate(self):
systemd.service( systemd.service(
@@ -64,5 +65,6 @@ class MtailDeployer(Deployer):
running=bool(self.mtail_address), running=bool(self.mtail_address),
enabled=bool(self.mtail_address), enabled=bool(self.mtail_address),
restarted=self.need_restart, restarted=self.need_restart,
daemon_reload=self.unit_changed,
) )
self.need_restart = False self.need_restart = False

View File

@@ -1,11 +1,13 @@
[Unit] [Unit]
Description=mtail Description=mtail
After=multi-user.target After=network-online.target
Wants=network-online.target
[Service] [Service]
Type=simple Type=simple
ExecStart=/bin/sh -c "journalctl -f -o short-iso -n 0 | /usr/local/bin/mtail --address={{ address }} --port={{ port }} --progs /etc/mtail --logtostderr --logs -" ExecStart=/bin/sh -c "journalctl -f -o short-iso -n 0 | /usr/local/bin/mtail --address={{ address }} --port={{ port }} --progs /etc/mtail --logtostderr --logs -"
Restart=on-failure Restart=on-failure
RestartSec=2s
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target