mirror of
https://github.com/chatmail/relay.git
synced 2026-05-11 16:34:39 +00:00
Compare commits
7 Commits
docs-inter
...
hagi/metri
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8349416024 | ||
|
|
6dd54fc0ed | ||
|
|
2aae3a1c2e | ||
|
|
0023af4d79 | ||
|
|
f40e04f9dc | ||
|
|
84ec0c13cc | ||
|
|
50f0be2e1d |
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
## untagged
|
## untagged
|
||||||
|
|
||||||
|
- run metrics generation with systemd-timer instead of cron
|
||||||
|
([#304](https://github.com/deltachat/chatmail/pull/304))
|
||||||
|
|
||||||
- change default for delete_mails_after from 40 to 20 days
|
- change default for delete_mails_after from 40 to 20 days
|
||||||
([#300]https://github.com/deltachat/chatmail/pull/300)
|
([#300]https://github.com/deltachat/chatmail/pull/300)
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ from pyinfra.operations import apt, files, pip, server, systemd
|
|||||||
|
|
||||||
from .acmetool import deploy_acmetool
|
from .acmetool import deploy_acmetool
|
||||||
|
|
||||||
|
root_owned = dict(user="root", group="root", mode="644")
|
||||||
|
|
||||||
def _build_chatmaild(dist_dir) -> None:
|
def _build_chatmaild(dist_dir) -> None:
|
||||||
dist_dir = Path(dist_dir).resolve()
|
dist_dir = Path(dist_dir).resolve()
|
||||||
@@ -50,7 +51,6 @@ def _install_remote_venv_with_chatmaild(config) -> None:
|
|||||||
remote_dist_file = f"{remote_base_dir}/dist/{dist_file.name}"
|
remote_dist_file = f"{remote_base_dir}/dist/{dist_file.name}"
|
||||||
remote_venv_dir = f"{remote_base_dir}/venv"
|
remote_venv_dir = f"{remote_base_dir}/venv"
|
||||||
remote_chatmail_inipath = f"{remote_base_dir}/chatmail.ini"
|
remote_chatmail_inipath = f"{remote_base_dir}/chatmail.ini"
|
||||||
root_owned = dict(user="root", group="root", mode="644")
|
|
||||||
|
|
||||||
apt.packages(
|
apt.packages(
|
||||||
name="apt install python3-virtualenv",
|
name="apt install python3-virtualenv",
|
||||||
@@ -85,9 +85,19 @@ def _install_remote_venv_with_chatmaild(config) -> None:
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# create metrics every 5 minutes via systemd
|
||||||
|
|
||||||
|
files.put(
|
||||||
|
name="Upload metrics.timer",
|
||||||
|
src=importlib.resources.files(__package__).joinpath("service/metrics.timer"),
|
||||||
|
dest=f"/etc/systemd/system/metrics.timer",
|
||||||
|
**root_owned,
|
||||||
|
)
|
||||||
|
|
||||||
files.template(
|
files.template(
|
||||||
src=importlib.resources.files(__package__).joinpath("metrics.cron.j2"),
|
name="upload metrics.service",
|
||||||
dest="/etc/cron.d/chatmail-metrics",
|
src=importlib.resources.files(__package__).joinpath("service/metrics.service.j2"),
|
||||||
|
dest="/etc/systemd/system/metrics.service",
|
||||||
user="root",
|
user="root",
|
||||||
group="root",
|
group="root",
|
||||||
mode="644",
|
mode="644",
|
||||||
@@ -97,6 +107,15 @@ def _install_remote_venv_with_chatmaild(config) -> None:
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
systemd.service(
|
||||||
|
name=f"Setup metrics timer",
|
||||||
|
service="metrics.timer",
|
||||||
|
running=True,
|
||||||
|
enabled=True,
|
||||||
|
restarted=True,
|
||||||
|
daemon_reload=True,
|
||||||
|
)
|
||||||
|
|
||||||
# install systemd units
|
# install systemd units
|
||||||
for fn in (
|
for fn in (
|
||||||
"doveauth",
|
"doveauth",
|
||||||
@@ -352,6 +371,23 @@ def _configure_dovecot(config: Config, debug: bool = False) -> bool:
|
|||||||
commands=["/usr/bin/sievec /etc/dovecot/default.sieve"],
|
commands=["/usr/bin/sievec /etc/dovecot/default.sieve"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
files.template(
|
||||||
|
src=importlib.resources.files(__package__).joinpath("service/expunge.service.j2"),
|
||||||
|
dest="/etc/systemd/system/expunge.service",
|
||||||
|
config={
|
||||||
|
"mail_domain": config.mail_domain,
|
||||||
|
"delete_mails_after": config.delete_mails_after,
|
||||||
|
},
|
||||||
|
**root_owned,
|
||||||
|
)
|
||||||
|
|
||||||
|
files.put(
|
||||||
|
name="Upload expunge.timer",
|
||||||
|
src=importlib.resources.files(__package__).joinpath("service/expunge.timer"),
|
||||||
|
dest=f"/etc/systemd/system/expunge.timer",
|
||||||
|
**root_owned,
|
||||||
|
)
|
||||||
|
|
||||||
files.template(
|
files.template(
|
||||||
src=importlib.resources.files(__package__).joinpath("dovecot/expunge.cron.j2"),
|
src=importlib.resources.files(__package__).joinpath("dovecot/expunge.cron.j2"),
|
||||||
dest="/etc/cron.d/expunge",
|
dest="/etc/cron.d/expunge",
|
||||||
@@ -523,6 +559,7 @@ def deploy_chatmail(config_path: Path) -> None:
|
|||||||
"systemctl reset-failed unbound.service",
|
"systemctl reset-failed unbound.service",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
systemd.service(
|
systemd.service(
|
||||||
name="Start and enable unbound",
|
name="Start and enable unbound",
|
||||||
service="unbound.service",
|
service="unbound.service",
|
||||||
|
|||||||
16
cmdeploy/src/cmdeploy/service/expunge.service.j2
Normal file
16
cmdeploy/src/cmdeploy/service/expunge.service.j2
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Expunge old mails after {{ config.delete_mails_after }} days
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
# delete all mails after {{ config.delete_mails_after }} days, in the Inbox
|
||||||
|
ExecStart=/home/vmail/mail/{{ config.mail_domain }} -path '*/cur/*' -mtime +{{ config.delete_mails_after }} -type f -delete
|
||||||
|
# or in any IMAP subfolder
|
||||||
|
ExecStart=vmail find /home/vmail/mail/{{ config.mail_domain }} -path '*/.*/cur/*' -mtime +{{ config.delete_mails_after }} -type f -delete
|
||||||
|
# even if they are unseen
|
||||||
|
ExecStart=vmail find /home/vmail/mail/{{ config.mail_domain }} -path '*/new/*' -mtime +{{ config.delete_mails_after }} -type f -delete
|
||||||
|
ExecStart=vmail find /home/vmail/mail/{{ config.mail_domain }} -path '*/new/*' -mtime +{{ config.delete_mails_after }} -type f -delete
|
||||||
|
# or only temporary (but then they shouldn't be around after {{ config.delete_mails_after }} days anyway).
|
||||||
|
ExecStart=vmail find /home/vmail/mail/{{ config.mail_domain }} -path '*/tmp/*' -mtime +{{ config.delete_mails_after }} -type f -delete
|
||||||
|
ExecStart=vmail find /home/vmail/mail/{{ config.mail_domain }} -path '*/.*/tmp/*' -mtime +{{ config.delete_mails_after }} -type f -delete
|
||||||
|
ExecStart=vmail find /home/vmail/mail/{{ config.mail_domain }} -name 'maildirsize' -type f -delete
|
||||||
9
cmdeploy/src/cmdeploy/service/expunge.timer
Normal file
9
cmdeploy/src/cmdeploy/service/expunge.timer
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Run expunge.service daily
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=weekly
|
||||||
|
Persistent=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
5
cmdeploy/src/cmdeploy/service/metrics.service.j2
Normal file
5
cmdeploy/src/cmdeploy/service/metrics.service.j2
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Generate metrics in /var/www/html/metrics
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart={{ config.execpath }} /home/vmail/mail/{{ config.mail_domain }} > /var/www/html/metrics
|
||||||
9
cmdeploy/src/cmdeploy/service/metrics.timer
Normal file
9
cmdeploy/src/cmdeploy/service/metrics.timer
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Run metrics.service every 5 minutes
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnBootSec=5min
|
||||||
|
OnUnitActiveSec=5min
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
Reference in New Issue
Block a user