1
0
mirror of https://github.com/mailcow/mailcow-dockerized.git synced 2025-12-19 21:01:31 +00:00

Optimize python bootstrapper

This commit is contained in:
FreddleSpl0it
2025-05-23 09:49:08 +02:00
parent 5f93ff04a9
commit eb7d2628ac
10 changed files with 164 additions and 114 deletions

View File

@@ -10,42 +10,35 @@ def main():
signal.signal(signal.SIGTERM, handle_sigterm)
container_name = os.getenv("CONTAINER_NAME")
service_name = container_name.replace("-mailcow", "").replace("-", "")
module_name = f"Bootstrap{service_name.capitalize()}"
if container_name == "sogo-mailcow":
from modules.BootstrapSogo import Bootstrap
elif container_name == "nginx-mailcow":
from modules.BootstrapNginx import Bootstrap
elif container_name == "postfix-mailcow":
from modules.BootstrapPostfix import Bootstrap
elif container_name == "dovecot-mailcow":
from modules.BootstrapDovecot import Bootstrap
elif container_name == "rspamd-mailcow":
from modules.BootstrapRspamd import Bootstrap
elif container_name == "clamd-mailcow":
from modules.BootstrapClamd import Bootstrap
elif container_name == "mysql-mailcow":
from modules.BootstrapMysql import Bootstrap
elif container_name == "php-fpm-mailcow":
from modules.BootstrapPhpfpm import Bootstrap
else:
print(f"No bootstrap handler for container: {container_name}", file=sys.stderr)
try:
mod = __import__(f"modules.{module_name}", fromlist=[module_name])
Bootstrap = getattr(mod, module_name)
except (ImportError, AttributeError) as e:
print(f"Failed to load bootstrap module for: {container_name}{module_name}")
print(str(e))
sys.exit(1)
b = Bootstrap(
container=container_name,
service=service_name,
db_config={
"host": "localhost",
"user": os.getenv("DBUSER") or os.getenv("MYSQL_USER"),
"password": os.getenv("DBPASS") or os.getenv("MYSQL_PASSWORD"),
"database": os.getenv("DBNAME") or os.getenv("MYSQL_DATABASE"),
"unix_socket": "/var/run/mysqld/mysqld.sock",
'connection_timeout': 2
'connection_timeout': 2,
'service_table': "service_settings",
'service_types': [service_name]
},
db_table="service_settings",
db_settings=['sogo'],
redis_config={
"host": os.getenv("REDIS_SLAVEOF_IP") or "redis-mailcow",
"port": int(os.getenv("REDIS_SLAVEOF_PORT") or 6379),
"read_host": "redis-mailcow",
"read_port": 6379,
"write_host": os.getenv("REDIS_SLAVEOF_IP") or "redis-mailcow",
"write_port": int(os.getenv("REDIS_SLAVEOF_PORT") or 6379),
"password": os.getenv("REDISPASS"),
"db": 0
}