[NEW] Automatic install mailhog. Mailhog integration in Odoo
This commit is contained in:
40
mailcatcher_menu/hooks.py
Normal file
40
mailcatcher_menu/hooks.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# Copyright 2024 Open2Bizz <info@open2bizz.nl>
|
||||
# License LGPL-3
|
||||
|
||||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def post_init_hook(env):
|
||||
"""Install MailHog as a systemd service when the module is installed."""
|
||||
script_path = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
'install_mailhog_as_service.sh',
|
||||
)
|
||||
|
||||
if not os.path.isfile(script_path):
|
||||
_logger.error("MailHog install script not found at %s", script_path)
|
||||
return
|
||||
|
||||
_logger.info("Running MailHog install script: %s", script_path)
|
||||
try:
|
||||
result = subprocess.run(
|
||||
['bash', script_path],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=300,
|
||||
)
|
||||
if result.returncode == 0:
|
||||
_logger.info("MailHog installed successfully.\n%s", result.stdout)
|
||||
else:
|
||||
_logger.error(
|
||||
"MailHog install script failed (exit %s):\n%s\n%s",
|
||||
result.returncode, result.stdout, result.stderr,
|
||||
)
|
||||
except subprocess.TimeoutExpired:
|
||||
_logger.error("MailHog install script timed out after 300 seconds")
|
||||
except Exception as e:
|
||||
_logger.error("Failed to run MailHog install script: %s", e)
|
||||
Reference in New Issue
Block a user