diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cda321c..d5dd7e4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/cmdeploy/src/cmdeploy/__init__.py b/cmdeploy/src/cmdeploy/__init__.py index 3454086e..b0c66fdf 100644 --- a/cmdeploy/src/cmdeploy/__init__.py +++ b/cmdeploy/src/cmdeploy/__init__.py @@ -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, ) diff --git a/cmdeploy/src/cmdeploy/opendkim/systemd.conf b/cmdeploy/src/cmdeploy/opendkim/systemd.conf new file mode 100644 index 00000000..0e150af7 --- /dev/null +++ b/cmdeploy/src/cmdeploy/opendkim/systemd.conf @@ -0,0 +1,3 @@ +[Service] +Restart=always +RuntimeMaxSec=1d diff --git a/cmdeploy/src/cmdeploy/tests/online/test_1_basic.py b/cmdeploy/src/cmdeploy/tests/online/test_1_basic.py index 93e05846..e311bc0a 100644 --- a/cmdeploy/src/cmdeploy/tests/online/test_1_basic.py +++ b/cmdeploy/src/cmdeploy/tests/online/test_1_basic.py @@ -1,3 +1,4 @@ +import datetime import smtplib import pytest @@ -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)