2018-07-26 21:41:11 +02:00
|
|
|
#!/usr/bin/python3
|
2017-09-24 14:42:40 +02:00
|
|
|
|
|
|
|
import jinja2
|
|
|
|
import os
|
|
|
|
import socket
|
|
|
|
import glob
|
2018-07-26 21:41:11 +02:00
|
|
|
import multiprocessing
|
2018-10-07 00:39:02 +02:00
|
|
|
import tenacity
|
2018-07-26 21:41:11 +02:00
|
|
|
|
2018-10-06 23:32:05 +02:00
|
|
|
from tenacity import retry
|
2018-07-26 21:41:11 +02:00
|
|
|
from podop import run_server
|
|
|
|
|
|
|
|
|
|
|
|
def start_podop():
|
|
|
|
os.setuid(8)
|
2018-09-27 14:53:58 +02:00
|
|
|
run_server(3 if "DEBUG" in os.environ else 0, "dovecot", "/tmp/podop.socket", [
|
2018-09-27 07:55:54 +02:00
|
|
|
("quota", "url", "http://admin/internal/dovecot/§"),
|
|
|
|
("auth", "url", "http://admin/internal/dovecot/§"),
|
|
|
|
("sieve", "url", "http://admin/internal/dovecot/§"),
|
2018-07-26 21:41:11 +02:00
|
|
|
])
|
2017-11-10 16:54:41 +02:00
|
|
|
|
2017-09-24 14:42:40 +02:00
|
|
|
convert = lambda src, dst: open(dst, "w").write(jinja2.Template(open(src).read()).render(**os.environ))
|
|
|
|
|
2018-10-22 16:02:43 +02:00
|
|
|
#@retry(stop=tenacity.stop_after_attempt(100), wait=tenacity.wait_random(min=2, max=5))
|
|
|
|
#def resolve():
|
|
|
|
# os.environ["FRONT_ADDRESS"] = socket.gethostbyname(os.environ.get("FRONT_ADDRESS", "front"))
|
|
|
|
# os.environ["REDIS_ADDRESS"] = socket.gethostbyname(os.environ.get("REDIS_ADDRESS", "redis"))
|
|
|
|
# if os.environ["WEBMAIL"] != "none":
|
|
|
|
# os.environ["WEBMAIL_ADDRESS"] = socket.gethostbyname(os.environ.get("WEBMAIL_ADDRESS", "webmail"))
|
2017-09-24 14:42:40 +02:00
|
|
|
|
|
|
|
# Actual startup script
|
2018-10-22 16:02:43 +02:00
|
|
|
#resolve()
|
|
|
|
resolve = retry(socket.gethostbyname, stop=tenacity.stop_after_attempt(100), wait=tenacity.wait_random(min=2, max=5))
|
|
|
|
os.environ["FRONT_ADDRESS"] = resolve(os.environ.get("FRONT_ADDRESS", "front"))
|
|
|
|
os.environ["REDIS_ADDRESS"] = resolve(os.environ.get("REDIS_ADDRESS", "redis"))
|
|
|
|
if os.environ["WEBMAIL"] != "none":
|
|
|
|
os.environ["WEBMAIL_ADDRESS"] = resolve(os.environ.get("WEBMAIL_ADDRESS", "webmail"))
|
2017-09-24 14:42:40 +02:00
|
|
|
|
2018-09-27 16:13:02 +02:00
|
|
|
for dovecot_file in glob.glob("/conf/*.conf"):
|
2017-09-24 15:44:44 +02:00
|
|
|
convert(dovecot_file, os.path.join("/etc/dovecot", os.path.basename(dovecot_file)))
|
2017-09-24 14:42:40 +02:00
|
|
|
|
2018-07-26 21:41:11 +02:00
|
|
|
# Run Podop, then postfix
|
|
|
|
multiprocessing.Process(target=start_podop).start()
|
2018-10-17 18:48:59 +02:00
|
|
|
os.system("chown -R mail: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"])
|