Skip to content

Commit

Permalink
opendkim: restart once every day (#498)
Browse files Browse the repository at this point in the history
fix #495
  • Loading branch information
missytake authored Feb 19, 2025
1 parent 2780f53 commit e928a33
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
- journald: remove old logs from disk
([#490](https://github.com/deltachat/chatmail/pull/490))

- opendkim: restart once every day to mend RAM leaks
([#498](https://github.com/chatmail/chatmail/pull/498)

- migration guide: let opendkim own the DKIM keys directory
([#468](https://github.com/deltachat/chatmail/pull/468))

Expand Down
9 changes: 9 additions & 0 deletions cmdeploy/src/cmdeploy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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,
)

Expand Down
3 changes: 3 additions & 0 deletions cmdeploy/src/cmdeploy/opendkim/systemd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Service]
Restart=always
RuntimeMaxSec=1d
9 changes: 9 additions & 0 deletions cmdeploy/src/cmdeploy/tests/online/test_1_basic.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import smtplib

import pytest
Expand Down Expand Up @@ -52,6 +53,14 @@ def test_exception(self, sshexec, capsys):
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)
Expand Down

0 comments on commit e928a33

Please # to comment.