1
0
mirror of https://github.com/Mailu/Mailu.git synced 2024-12-14 10:53:30 +02:00
Mailu/core/dovecot/start.py

42 lines
1.4 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import os
import glob
2018-07-26 21:41:11 +02:00
import multiprocessing
import logging as log
import sys
2018-07-26 21:41:11 +02:00
2021-10-29 15:34:00 +02:00
from podop import run_server
from socrate import system, conf
2018-07-26 21:41:11 +02:00
2019-01-08 05:16:05 +02:00
log.basicConfig(stream=sys.stderr, level=os.environ.get("LOG_LEVEL", "WARNING"))
2018-07-26 21:41:11 +02:00
def start_podop():
os.setuid(8)
url = "http://" + os.environ["ADMIN_ADDRESS"] + "/internal/dovecot/§"
run_server(0, "dovecot", "/tmp/podop.socket", [
("quota", "url", url ),
("auth", "url", url),
("sieve", "url", url),
2018-07-26 21:41:11 +02:00
])
# Actual startup script
os.environ["FRONT_ADDRESS"] = system.get_host_address_from_environment("FRONT", "front")
os.environ["ADMIN_ADDRESS"] = system.get_host_address_from_environment("ADMIN", "admin")
os.environ["ANTISPAM_WEBUI_ADDRESS"] = system.get_host_address_from_environment("ANTISPAM_WEBUI", "antispam:11334")
2018-09-27 16:13:02 +02:00
for dovecot_file in glob.glob("/conf/*.conf"):
conf.jinja(dovecot_file, os.environ, os.path.join("/etc/dovecot", os.path.basename(dovecot_file)))
os.makedirs("/conf/bin", exist_ok=True)
for script_file in glob.glob("/conf/*.script"):
out_file = os.path.join("/conf/bin/", os.path.basename(script_file).replace('.script',''))
conf.jinja(script_file, os.environ, out_file)
2019-10-03 10:32:36 +02:00
os.chmod(out_file, 0o555)
2018-07-26 21:41:11 +02:00
# Run Podop, then postfix
multiprocessing.Process(target=start_podop).start()
os.system("chown mail:mail /mail")
os.system("chown -R mail:mail /var/lib/dovecot /conf")
2017-09-24 15:44:44 +02:00
os.execv("/usr/sbin/dovecot", ["dovecot", "-c", "/etc/dovecot/dovecot.conf", "-F"])