1
0
mirror of https://github.com/zokradonh/kopano-docker synced 2025-06-23 15:56:37 +00:00

convert kcconf.py to unix line endings

add *:236 to default config
add healthckeck script

Signed-off-by: Felix Bartels <felix@host-consultants.de>
This commit is contained in:
Felix Bartels 2018-11-05 08:03:24 +01:00
parent 4dd68c9499
commit 0aaba5224e
4 changed files with 91 additions and 78 deletions

View File

@ -47,3 +47,6 @@ COPY kcconf.py defaultconfigs/ start-service.sh /kopano/
ENTRYPOINT ["/usr/bin/dumb-init", "--"] ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD [ "/kopano/start-service.sh" ] CMD [ "/kopano/start-service.sh" ]
HEALTHCHECK --interval=30s --timeout=60s \
CMD /kopano/healthcheck.sh

View File

@ -9,7 +9,7 @@ kcconf.configkopano({
'log_level': "3", 'log_level': "3",
'attachment_path': "/kopano/data/attachments/", 'attachment_path': "/kopano/data/attachments/",
'user_plugin': "ldap", 'user_plugin': "ldap",
'server_listen': "", 'server_listen': "*:236",
'server_listen_tls': "*:237" 'server_listen_tls': "*:237"
} }
}) })

10
core/healthcheck.sh Normal file
View File

@ -0,0 +1,10 @@
#!/bin/bash
case "$SERVICE_TO_START" in
server)
dockerize \
-wait tcp://localhost:237 \
([ -f /kopano/data/.user-sync ] || kopano-cli --sync; touch /kopano/data/.user-sync)
exit 0
;;
esac

View File

@ -1,77 +1,77 @@
"""This module provides functions for easy editing of kopano config files """This module provides functions for easy editing of kopano config files
via environment variables""" via environment variables"""
import re import re
import os import os
import os.path import os.path
def configkopano(configs): def configkopano(configs):
""" Changes configuration files according to configs typically returned from parseenvironmentvariables(..)""" """ Changes configuration files according to configs typically returned from parseenvironmentvariables(..)"""
for filename, config in configs.items(): for filename, config in configs.items():
if not os.path.exists(filename): if not os.path.exists(filename):
return return
# read configuration file # read configuration file
with open(filename) as f: with open(filename) as f:
contents = f.read() contents = f.read()
f.close() f.close()
for key, newvalue in config.items(): for key, newvalue in config.items():
if key == "kccomment": if key == "kccomment":
# comment lines # comment lines
for line in newvalue: for line in newvalue:
contents = re.sub(r"^\s*" + re.escape(line), r"#{}".format(line), contents, 0, re.MULTILINE) contents = re.sub(r"^\s*" + re.escape(line), r"#{}".format(line), contents, 0, re.MULTILINE)
elif key == "kcuncomment": elif key == "kcuncomment":
# uncomment lines # uncomment lines
for line in newvalue: for line in newvalue:
contents = re.sub(r"^\s*#\s*" + re.escape(line) , line, contents, 0, re.MULTILINE) contents = re.sub(r"^\s*#\s*" + re.escape(line) , line, contents, 0, re.MULTILINE)
else: else:
# find config line # find config line
if re.search(r"^\s*#?\s*{}\s*=.*".format(key), contents, re.MULTILINE) == None: if re.search(r"^\s*#?\s*{}\s*=.*".format(key), contents, re.MULTILINE) == None:
# add configuration as new line # add configuration as new line
contents += "\n{} = {}".format(key, newvalue) contents += "\n{} = {}".format(key, newvalue)
else: else:
# change existing line # change existing line
contents = re.sub(r"^\s*#?\s*{}\s*=.*".format(key), r"{} = {}".format(key, newvalue), contents, 0, re.MULTILINE) contents = re.sub(r"^\s*#?\s*{}\s*=.*".format(key), r"{} = {}".format(key, newvalue), contents, 0, re.MULTILINE)
# save new configuration # save new configuration
with open(filename, "w") as f: with open(filename, "w") as f:
f.write(contents) f.write(contents)
f.close() f.close()
def parseenvironmentvariables(prependingpath): def parseenvironmentvariables(prependingpath):
""" Parse all environment variables starting with KCCONF_, KCCOMMENT_ and KCUNCOMMENT_ and """ Parse all environment variables starting with KCCONF_, KCCOMMENT_ and KCUNCOMMENT_ and
return as multi dimensional dict """ return as multi dimensional dict """
configs = dict() configs = dict()
for name, value in os.environ.items(): for name, value in os.environ.items():
# parse change/add configuration commands # parse change/add configuration commands
namematch = re.match(r"^KCCONF_([A-Z]+)_([A-Z0-9_]+)$", name) namematch = re.match(r"^KCCONF_([A-Z]+)_([A-Z0-9_]+)$", name)
if namematch != None: if namematch != None:
filename = namematch.group(1).lower() + ".cfg" filename = namematch.group(1).lower() + ".cfg"
if prependingpath + filename not in configs: if prependingpath + filename not in configs:
configs[prependingpath + filename] = dict() configs[prependingpath + filename] = dict()
confkey = namematch.group(2).lower() confkey = namematch.group(2).lower()
configs[prependingpath + filename][confkey] = value configs[prependingpath + filename][confkey] = value
# parse comment configuration commands # parse comment configuration commands
commentmatch = re.match(r"^KCCOMMENT_([A-Z]+)_([A-Z0-9_]+)$", name) commentmatch = re.match(r"^KCCOMMENT_([A-Z]+)_([A-Z0-9_]+)$", name)
if commentmatch != None: if commentmatch != None:
filename = commentmatch.group(1).lower() + ".cfg" filename = commentmatch.group(1).lower() + ".cfg"
if prependingpath + filename not in configs: if prependingpath + filename not in configs:
configs[prependingpath + filename] = dict() configs[prependingpath + filename] = dict()
try: try:
configs[prependingpath + filename]["kccomment"].append(value) configs[prependingpath + filename]["kccomment"].append(value)
except KeyError: except KeyError:
configs[prependingpath + filename]["kccomment"] = [] configs[prependingpath + filename]["kccomment"] = []
configs[prependingpath + filename]["kccomment"].append(value) configs[prependingpath + filename]["kccomment"].append(value)
# parse uncomment configuration commands # parse uncomment configuration commands
uncommentmatch = re.match(r"^KCUNCOMMENT_([A-Z]+)_([A-Z0-9_]+)$", name) uncommentmatch = re.match(r"^KCUNCOMMENT_([A-Z]+)_([A-Z0-9_]+)$", name)
if uncommentmatch != None: if uncommentmatch != None:
filename = uncommentmatch.group(1).lower() + ".cfg" filename = uncommentmatch.group(1).lower() + ".cfg"
if prependingpath + filename not in configs: if prependingpath + filename not in configs:
configs[prependingpath + filename] = dict() configs[prependingpath + filename] = dict()
try: try:
configs[prependingpath + filename]["kcuncomment"].append(value) configs[prependingpath + filename]["kcuncomment"].append(value)
except KeyError: except KeyError:
configs[prependingpath + filename]["kcuncomment"] = [] configs[prependingpath + filename]["kcuncomment"] = []
configs[prependingpath + filename]["kcuncomment"].append(value) configs[prependingpath + filename]["kcuncomment"].append(value)
return configs return configs