main.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import os
  2. import sys
  3. import signal
  4. def handle_sigterm(signum, frame):
  5. print("Received SIGTERM, exiting gracefully...")
  6. sys.exit(0)
  7. def main():
  8. signal.signal(signal.SIGTERM, handle_sigterm)
  9. container_name = os.getenv("CONTAINER_NAME")
  10. service_name = container_name.replace("-mailcow", "").replace("-", "")
  11. module_name = f"Bootstrap{service_name.capitalize()}"
  12. try:
  13. mod = __import__(f"modules.{module_name}", fromlist=[module_name])
  14. Bootstrap = getattr(mod, module_name)
  15. except (ImportError, AttributeError) as e:
  16. print(f"Failed to load bootstrap module for: {container_name} → {module_name}")
  17. print(str(e))
  18. sys.exit(1)
  19. b = Bootstrap(
  20. container=container_name,
  21. service=service_name,
  22. db_config={
  23. "host": "localhost",
  24. "user": os.getenv("DBUSER") or os.getenv("MYSQL_USER"),
  25. "password": os.getenv("DBPASS") or os.getenv("MYSQL_PASSWORD"),
  26. "database": os.getenv("DBNAME") or os.getenv("MYSQL_DATABASE"),
  27. "unix_socket": "/var/run/mysqld/mysqld.sock",
  28. 'connection_timeout': 2,
  29. 'service_table': "service_settings",
  30. 'service_types': [service_name]
  31. },
  32. redis_config={
  33. "read_host": "redis-mailcow",
  34. "read_port": 6379,
  35. "write_host": os.getenv("REDIS_SLAVEOF_IP") or "redis-mailcow",
  36. "write_port": int(os.getenv("REDIS_SLAVEOF_PORT") or 6379),
  37. "password": os.getenv("REDISPASS"),
  38. "db": 0
  39. }
  40. )
  41. b.bootstrap()
  42. if __name__ == "__main__":
  43. main()