From 6c37dcfa03f75bb599563042c5a7fa5a0b1be64e Mon Sep 17 00:00:00 2001 From: Stephane de Labrusse Date: Thu, 28 Sep 2023 11:03:32 +0200 Subject: [PATCH] Events.mail-settings-changed registered --- .../mail-settings-changed/80start_services | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 imageroot/events/mail-settings-changed/80start_services diff --git a/imageroot/events/mail-settings-changed/80start_services b/imageroot/events/mail-settings-changed/80start_services new file mode 100755 index 00000000..d5f1a058 --- /dev/null +++ b/imageroot/events/mail-settings-changed/80start_services @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +# +# Copyright (C) 2022 Nethesis S.r.l.s +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import json +import sys +import agent +import os + +event = json.load(sys.stdin) + +if event['module_uuid'] == os.getenv('MAIL_SERVER', ''): + # Restart to apply changed settings + rdb = agent.redis_connect() + + # retrieve mail module_hostname from module_uuid + mail_server = os.environ["MAIL_SERVER"] + providers = agent.list_service_providers(rdb, 'imap', 'tcp', { + 'module_uuid': mail_server, + }) + mail_hostname = providers[0]["mail_hostname"] + agent.set_env("MAIL_HOSTNAME",mail_hostname) + agent.run_helper("systemctl", "--user", "try-restart", "imapsync.service").check_returncode()