|
22 | 22 | from .acmetool import AcmetoolDeployer |
23 | 23 | from .basedeploy import Deployer, Deployment, get_resource |
24 | 24 | from .opendkim.deployer import OpendkimDeployer |
| 25 | +from .postfix.deployer import PostfixDeployer |
25 | 26 | from .www import build_webpages, find_merge_conflict, get_paths |
26 | 27 |
|
27 | 28 |
|
@@ -251,85 +252,6 @@ def activate(self): |
251 | 252 | ) |
252 | 253 |
|
253 | 254 |
|
254 | | -def _configure_postfix(config: Config, debug: bool = False) -> bool: |
255 | | - """Configures Postfix SMTP server.""" |
256 | | - need_restart = False |
257 | | - |
258 | | - main_config = files.template( |
259 | | - src=get_resource("postfix/main.cf.j2"), |
260 | | - dest="/etc/postfix/main.cf", |
261 | | - user="root", |
262 | | - group="root", |
263 | | - mode="644", |
264 | | - config=config, |
265 | | - disable_ipv6=config.disable_ipv6, |
266 | | - ) |
267 | | - need_restart |= main_config.changed |
268 | | - |
269 | | - master_config = files.template( |
270 | | - src=get_resource("postfix/master.cf.j2"), |
271 | | - dest="/etc/postfix/master.cf", |
272 | | - user="root", |
273 | | - group="root", |
274 | | - mode="644", |
275 | | - debug=debug, |
276 | | - config=config, |
277 | | - ) |
278 | | - need_restart |= master_config.changed |
279 | | - |
280 | | - header_cleanup = files.put( |
281 | | - src=get_resource("postfix/submission_header_cleanup"), |
282 | | - dest="/etc/postfix/submission_header_cleanup", |
283 | | - user="root", |
284 | | - group="root", |
285 | | - mode="644", |
286 | | - ) |
287 | | - need_restart |= header_cleanup.changed |
288 | | - |
289 | | - # Login map that 1:1 maps email address to login. |
290 | | - login_map = files.put( |
291 | | - src=get_resource("postfix/login_map"), |
292 | | - dest="/etc/postfix/login_map", |
293 | | - user="root", |
294 | | - group="root", |
295 | | - mode="644", |
296 | | - ) |
297 | | - need_restart |= login_map.changed |
298 | | - |
299 | | - return need_restart |
300 | | - |
301 | | - |
302 | | -class PostfixDeployer(Deployer): |
303 | | - required_users = [("postfix", None, ["opendkim"])] |
304 | | - |
305 | | - def __init__(self, config, disable_mail): |
306 | | - self.config = config |
307 | | - self.disable_mail = disable_mail |
308 | | - |
309 | | - def install(self): |
310 | | - apt.packages( |
311 | | - name="Install Postfix", |
312 | | - packages="postfix", |
313 | | - ) |
314 | | - |
315 | | - def configure(self): |
316 | | - self.need_restart = _configure_postfix(self.config) |
317 | | - |
318 | | - def activate(self): |
319 | | - restart = False if self.disable_mail else self.need_restart |
320 | | - |
321 | | - systemd.service( |
322 | | - name="disable postfix for now" |
323 | | - if self.disable_mail |
324 | | - else "Start and enable Postfix", |
325 | | - service="postfix.service", |
326 | | - running=False if self.disable_mail else True, |
327 | | - enabled=False if self.disable_mail else True, |
328 | | - restarted=restart, |
329 | | - ) |
330 | | - self.need_restart = False |
331 | | - |
332 | | - |
333 | 255 | def _install_dovecot_package(package: str, arch: str): |
334 | 256 | arch = "amd64" if arch == "x86_64" else arch |
335 | 257 | arch = "arm64" if arch == "aarch64" else arch |
|
0 commit comments