opendkim: restart once every day (#498)

fix #495
This commit is contained in:
missytake
2025-02-19 21:50:48 +01:00
committed by GitHub
parent 2780f53d3b
commit e928a33f95
4 changed files with 24 additions and 0 deletions

View File

@@ -221,6 +221,14 @@ def _configure_opendkim(domain: str, dkim_selector: str = "dkim") -> bool:
_su_user="opendkim",
)
service_file = files.put(
name="Configure opendkim to restart once a day",
src=importlib.resources.files(__package__).joinpath("opendkim/systemd.conf"),
dest="/etc/systemd/system/opendkim.service.d/10-prevent-memory-leak.conf",
)
need_restart |= service_file.changed
return need_restart
@@ -653,6 +661,7 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None:
service="opendkim.service",
running=True,
enabled=True,
daemon_reload=opendkim_need_restart,
restarted=opendkim_need_restart,
)

View File

@@ -0,0 +1,3 @@
[Service]
Restart=always
RuntimeMaxSec=1d

View File

@@ -1,3 +1,4 @@
import datetime
import smtplib
import pytest
@@ -52,6 +53,14 @@ class TestSSHExecutor:
else:
pytest.fail("didn't raise exception")
def test_opendkim_restarted(self, sshexec):
"""check that opendkim is not running for longer than a day."""
out = sshexec(call=remote.rshell.shell, kwargs=dict(command="systemctl status opendkim"))
assert type(out) == str
since_date_str = out.split("since ")[1].split(";")[0]
since_date = datetime.datetime.strptime(since_date_str, "%a %Y-%m-%d %H:%M:%S %Z")
assert (datetime.datetime.now() - since_date).total_seconds() < 60 * 60 * 24
def test_remote(remote, imap_or_smtp):
lineproducer = remote.iter_output(imap_or_smtp.logcmd)