|
1 | | -import os |
2 | 1 | import urllib.request |
3 | 2 |
|
4 | 3 | from chatmaild.config import Config |
5 | 4 | from pyinfra import host |
6 | 5 | from pyinfra.facts.deb import DebPackages |
7 | | -from pyinfra.facts.server import Arch, Sysctl |
| 6 | +from pyinfra.facts.server import Arch, Command, Sysctl |
8 | 7 | from pyinfra.operations import apt, files, server, systemd |
9 | 8 |
|
10 | 9 | from cmdeploy.basedeploy import ( |
@@ -153,19 +152,25 @@ def _configure_dovecot(config: Config, debug: bool = False) -> (bool, bool): |
153 | 152 |
|
154 | 153 | # as per https://doc.dovecot.org/2.3/configuration_manual/os/ |
155 | 154 | # it is recommended to set the following inotify limits |
156 | | - if not os.environ.get("CHATMAIL_NOSYSCTL"): |
157 | | - for name in ("max_user_instances", "max_user_watches"): |
158 | | - key = f"fs.inotify.{name}" |
159 | | - if host.get_fact(Sysctl)[key] > 65535: |
160 | | - # Skip updating limits if already sufficient |
161 | | - # (enables running in incus containers where sysctl readonly) |
162 | | - continue |
163 | | - server.sysctl( |
164 | | - name=f"Change {key}", |
165 | | - key=key, |
166 | | - value=65535, |
167 | | - persist=True, |
| 155 | + can_modify = host.get_fact(Command, "systemd-detect-virt -c || true") == "none" |
| 156 | + for name in ("max_user_instances", "max_user_watches"): |
| 157 | + key = f"fs.inotify.{name}" |
| 158 | + value = host.get_fact(Sysctl)[key] |
| 159 | + if value > 65534: |
| 160 | + continue |
| 161 | + if not can_modify: |
| 162 | + print( |
| 163 | + "\n!!!! refusing to attempt sysctl setting in shared-kernel containers\n" |
| 164 | + f"!!!! dovecot: sysctl {key!r}={value}, should be >65534 for production setups\n" |
| 165 | + "!!!!" |
168 | 166 | ) |
| 167 | + continue |
| 168 | + server.sysctl( |
| 169 | + name=f"Change {key}", |
| 170 | + key=key, |
| 171 | + value=65535, |
| 172 | + persist=True, |
| 173 | + ) |
169 | 174 |
|
170 | 175 | timezone_env = files.line( |
171 | 176 | name="Set TZ environment variable", |
|
0 commit comments